use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class BTreeAccessMethod method getNewConditionExprs.
private void getNewConditionExprs(Mutable<ILogicalExpression> conditionRef, Set<ILogicalExpression> replacedFuncExprs, List<Mutable<ILogicalExpression>> remainingFuncExprs) throws CompilationException {
remainingFuncExprs.clear();
if (replacedFuncExprs.isEmpty()) {
return;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) conditionRef.getValue();
if (replacedFuncExprs.size() == 1) {
Iterator<ILogicalExpression> it = replacedFuncExprs.iterator();
if (!it.hasNext()) {
return;
}
if (funcExpr == it.next()) {
// There are no remaining function exprs.
return;
}
}
// The original select cond must be an AND. Check it just to be sure.
if (funcExpr.getFunctionIdentifier() != AlgebricksBuiltinFunctions.AND) {
throw new CompilationException(ErrorCode.COMPILATION_FUNC_EXPRESSION_CANNOT_UTILIZE_INDEX, funcExpr.toString());
}
// Clean the conjuncts.
for (Mutable<ILogicalExpression> arg : funcExpr.getArguments()) {
ILogicalExpression argExpr = arg.getValue();
if (argExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
continue;
}
// plan, then add it to the list of remaining function expressions.
if (!replacedFuncExprs.contains(argExpr)) {
remainingFuncExprs.add(arg);
}
}
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class PullSelectOutOfEqJoin method isEqVarVar.
private boolean isEqVarVar(ILogicalExpression expr) {
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
if (!f.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.EQ)) {
return false;
}
ILogicalExpression e1 = f.getArguments().get(0).getValue();
if (e1.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
return false;
} else {
ILogicalExpression e2 = f.getArguments().get(1).getValue();
return e2.getExpressionTag() == LogicalExpressionTag.VARIABLE;
}
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class PushFunctionsBelowJoin method gatherFunctionCalls.
private void gatherFunctionCalls(Mutable<ILogicalExpression> exprRef, List<Mutable<ILogicalExpression>> funcExprs) {
AbstractLogicalExpression expr = (AbstractLogicalExpression) exprRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return;
}
// Check whether the function is a function we want to push.
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
if (toPushFuncIdents.contains(funcExpr.getFunctionIdentifier())) {
funcExprs.add(exprRef);
}
// Traverse arguments.
for (Mutable<ILogicalExpression> funcArg : funcExpr.getArguments()) {
gatherFunctionCalls(funcArg, funcExprs);
}
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class PullSelectOutOfEqJoin method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
if (op.getOperatorTag() != LogicalOperatorTag.INNERJOIN) {
return false;
}
AbstractBinaryJoinOperator join = (AbstractBinaryJoinOperator) op;
ILogicalExpression expr = join.getCondition().getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return false;
}
AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) expr;
FunctionIdentifier fi = fexp.getFunctionIdentifier();
if (!fi.equals(AlgebricksBuiltinFunctions.AND)) {
return false;
}
List<Mutable<ILogicalExpression>> eqVarVarComps = new ArrayList<Mutable<ILogicalExpression>>();
List<Mutable<ILogicalExpression>> otherPredicates = new ArrayList<Mutable<ILogicalExpression>>();
for (Mutable<ILogicalExpression> arg : fexp.getArguments()) {
if (isEqVarVar(arg.getValue())) {
eqVarVarComps.add(arg);
} else {
otherPredicates.add(arg);
}
}
if (eqVarVarComps.isEmpty() || otherPredicates.isEmpty()) {
return false;
}
// pull up
ILogicalExpression pulledCond = makeCondition(otherPredicates, context);
SelectOperator select = new SelectOperator(new MutableObject<ILogicalExpression>(pulledCond), false, null);
ILogicalExpression newJoinCond = makeCondition(eqVarVarComps, context);
join.getCondition().setValue(newJoinCond);
select.getInputs().add(new MutableObject<ILogicalOperator>(join));
opRef.setValue(select);
context.computeAndSetTypeEnvironmentForOperator(select);
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression in project asterixdb by apache.
the class FDsAndEquivClassesVisitor method fdsEqClassesForAbstractUnnestOperator.
private void fdsEqClassesForAbstractUnnestOperator(AbstractUnnestOperator op, IOptimizationContext ctx) throws AlgebricksException {
ILogicalOperator inp1 = op.getInputs().get(0).getValue();
Map<LogicalVariable, EquivalenceClass> eqClasses = getOrCreateEqClasses(op, ctx);
Map<LogicalVariable, EquivalenceClass> propagatedEqClasses = getOrComputeEqClasses(inp1, ctx);
/**
* The original eq classes of unnest-map are only for produced
* variables, therefore eqClasses and propagatedEqClasses do not have
* overlaps.
*/
eqClasses.putAll(propagatedEqClasses);
ctx.putEquivalenceClassMap(op, eqClasses);
List<FunctionalDependency> fds = getOrComputeFDs(inp1, ctx);
ctx.putFDList(op, fds);
ILogicalExpression expr = op.getExpressionRef().getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression afe = (AbstractFunctionCallExpression) expr;
if (afe.getKind() == FunctionKind.UNNEST && ((UnnestingFunctionCallExpression) afe).returnsUniqueValues()) {
List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(op, vars);
ArrayList<LogicalVariable> h = new ArrayList<LogicalVariable>();
h.addAll(op.getVariables());
FunctionalDependency fd = new FunctionalDependency(h, vars);
fds.add(fd);
}
}
}
Aggregations