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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations