Search in sources :

Example 1 with DistinctOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator in project asterixdb by apache.

the class AqlExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(DistinctClause dc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    List<Mutable<ILogicalExpression>> exprList = new ArrayList<>();
    Mutable<ILogicalOperator> input = null;
    for (Expression expr : dc.getDistinctByExpr()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(expr, tupSource);
        exprList.add(new MutableObject<ILogicalExpression>(p.first));
        input = p.second;
    }
    DistinctOperator opDistinct = new DistinctOperator(exprList);
    opDistinct.getInputs().add(input);
    return new Pair<>(opDistinct, null);
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) DistinctOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 2 with DistinctOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator in project asterixdb by apache.

the class SqlppExpressionToPlanTranslator method processSelectClause.

// Generates the return expression for a select clause.
private Pair<ILogicalOperator, LogicalVariable> processSelectClause(SelectBlock selectBlock, Mutable<ILogicalOperator> tupSrc) throws CompilationException {
    SelectClause selectClause = selectBlock.getSelectClause();
    Expression returnExpr;
    if (selectClause.selectElement()) {
        returnExpr = selectClause.getSelectElement().getExpression();
    } else {
        returnExpr = generateReturnExpr(selectClause, selectBlock);
    }
    Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(returnExpr, tupSrc);
    LogicalVariable returnVar;
    ILogicalOperator returnOperator;
    if (returnExpr.getKind() == Kind.VARIABLE_EXPRESSION) {
        VariableExpr varExpr = (VariableExpr) returnExpr;
        returnOperator = eo.second.getValue();
        returnVar = context.getVar(varExpr.getVar().getId());
    } else {
        returnVar = context.newVar();
        returnOperator = new AssignOperator(returnVar, new MutableObject<ILogicalExpression>(eo.first));
        returnOperator.getInputs().add(eo.second);
    }
    if (selectClause.distinct()) {
        DistinctOperator distinctOperator = new DistinctOperator(mkSingletonArrayList(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(returnVar))));
        distinctOperator.getInputs().add(new MutableObject<ILogicalOperator>(returnOperator));
        return new Pair<>(distinctOperator, returnVar);
    } else {
        return new Pair<>(returnOperator, returnVar);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) DistinctOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) UnnestingFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) MutableObject(org.apache.commons.lang3.mutable.MutableObject) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 3 with DistinctOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator in project asterixdb by apache.

the class ExtractDistinctByExpressionsRule method rewritePost.

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
    AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
    if (op1.getOperatorTag() != LogicalOperatorTag.DISTINCT) {
        return false;
    }
    if (context.checkIfInDontApplySet(this, op1)) {
        return false;
    }
    context.addToDontApplySet(this, op1);
    DistinctOperator d = (DistinctOperator) op1;
    boolean changed = false;
    Mutable<ILogicalOperator> opRef2 = d.getInputs().get(0);
    List<Mutable<ILogicalExpression>> newExprList = new ArrayList<Mutable<ILogicalExpression>>();
    for (Mutable<ILogicalExpression> expr : d.getExpressions()) {
        LogicalExpressionTag tag = expr.getValue().getExpressionTag();
        if (tag == LogicalExpressionTag.VARIABLE || tag == LogicalExpressionTag.CONSTANT) {
            newExprList.add(expr);
            continue;
        }
        LogicalVariable v = extractExprIntoAssignOpRef(expr.getValue(), opRef2, context);
        ILogicalExpression newExpr = new VariableReferenceExpression(v);
        newExprList.add(new MutableObject<ILogicalExpression>(newExpr));
        changed = true;
    }
    if (changed) {
        d.getExpressions().clear();
        d.getExpressions().addAll(newExprList);
        context.computeAndSetTypeEnvironmentForOperator(d);
    }
    return changed;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) DistinctOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) LogicalExpressionTag(org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)

Example 4 with DistinctOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator in project asterixdb by apache.

the class LogicalOperatorDeepCopyWithNewVariablesVisitor method visitDistinctOperator.

@Override
public ILogicalOperator visitDistinctOperator(DistinctOperator op, ILogicalOperator arg) throws AlgebricksException {
    DistinctOperator opCopy = new DistinctOperator(exprDeepCopyVisitor.deepCopyExpressionReferenceList(op.getExpressions()));
    deepCopyInputsAnnotationsAndExecutionMode(op, arg, opCopy);
    return opCopy;
}
Also used : DistinctOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator)

Example 5 with DistinctOperator

use of org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator in project asterixdb by apache.

the class IsomorphismOperatorVisitor method visitDistinctOperator.

@Override
public Boolean visitDistinctOperator(DistinctOperator op, ILogicalOperator arg) throws AlgebricksException {
    AbstractLogicalOperator aop = (AbstractLogicalOperator) arg;
    if (aop.getOperatorTag() != LogicalOperatorTag.DISTINCT) {
        return Boolean.FALSE;
    }
    DistinctOperator distinctOpArg = (DistinctOperator) copyAndSubstituteVar(op, arg);
    boolean isomorphic = compareExpressions(op.getExpressions(), distinctOpArg.getExpressions());
    return isomorphic;
}
Also used : AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) DistinctOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator)

Aggregations

DistinctOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator)5 Mutable (org.apache.commons.lang3.mutable.Mutable)3 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)3 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)3 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)3 ArrayList (java.util.ArrayList)2 Expression (org.apache.asterix.lang.common.base.Expression)2 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)2 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)2 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)1 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)1 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)1 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)1 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)1 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)1 LogicalExpressionTag (org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1