Search in sources :

Example 36 with Pair

use of org.apache.commons.lang3.tuple.Pair in project asterixdb by apache.

the class LangExpressionToPlanTranslator method aggListifyForSubquery.

protected Pair<ILogicalOperator, LogicalVariable> aggListifyForSubquery(LogicalVariable var, Mutable<ILogicalOperator> opRef, boolean bProject) {
    AggregateFunctionCallExpression funAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.LISTIFY, new ArrayList<>());
    funAgg.getArguments().add(new MutableObject<>(new VariableReferenceExpression(var)));
    LogicalVariable varListified = context.newSubplanOutputVar();
    AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified), mkSingletonArrayList(new MutableObject<>(funAgg)));
    agg.getInputs().add(opRef);
    ILogicalOperator res;
    if (bProject) {
        ProjectOperator pr = new ProjectOperator(varListified);
        pr.getInputs().add(new MutableObject<>(agg));
        res = pr;
    } else {
        res = agg;
    }
    return new Pair<>(res, varListified);
}
Also used : AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) MutableObject(org.apache.commons.lang3.mutable.MutableObject) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 37 with Pair

use of org.apache.commons.lang3.tuple.Pair in project asterixdb by apache.

the class LangExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(RecordConstructor rc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR));
    LogicalVariable v1 = context.newVar();
    AssignOperator a = new AssignOperator(v1, new MutableObject<>(f));
    Mutable<ILogicalOperator> topOp = tupSource;
    for (FieldBinding fb : rc.getFbList()) {
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(fb.getLeftExpr(), topOp);
        f.getArguments().add(new MutableObject<>(eo1.first));
        topOp = eo1.second;
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(fb.getRightExpr(), topOp);
        f.getArguments().add(new MutableObject<>(eo2.first));
        topOp = eo2.second;
    }
    a.getInputs().add(topOp);
    return new Pair<>(a, v1);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FieldBinding(org.apache.asterix.lang.common.expression.FieldBinding) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 38 with Pair

use of org.apache.commons.lang3.tuple.Pair in project asterixdb by apache.

the class SqlppExpressionToPlanTranslator method generateUnnestForBinaryCorrelateRightBranch.

private Pair<ILogicalOperator, LogicalVariable> generateUnnestForBinaryCorrelateRightBranch(AbstractBinaryCorrelateClause binaryCorrelate, Mutable<ILogicalOperator> inputOpRef, boolean innerUnnest) throws CompilationException {
    LogicalVariable rightVar = context.newVarFromExpression(binaryCorrelate.getRightVariable());
    Expression rightExpr = binaryCorrelate.getRightExpression();
    Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(rightExpr, inputOpRef);
    ILogicalOperator unnestOp;
    if (binaryCorrelate.hasPositionalVariable()) {
        LogicalVariable pVar = context.newVarFromExpression(binaryCorrelate.getPositionalVariable());
        // We set the positional variable type as BIGINT type.
        unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter()) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter());
    } else {
        unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first))) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)));
    }
    unnestOp.getInputs().add(eo.second);
    return new Pair<>(unnestOp, rightVar);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Mutable(org.apache.commons.lang3.mutable.Mutable) LeftOuterUnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestOperator) UnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator) 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) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) LeftOuterUnnestOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestOperator) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 39 with Pair

use of org.apache.commons.lang3.tuple.Pair 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 40 with Pair

use of org.apache.commons.lang3.tuple.Pair in project asterixdb by apache.

the class SqlppExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(Query q, Mutable<ILogicalOperator> tupSource) throws CompilationException {
    Expression queryBody = q.getBody();
    if (queryBody.getKind() == Kind.SELECT_EXPRESSION) {
        SelectExpression selectExpr = (SelectExpression) queryBody;
        if (q.isTopLevel()) {
            selectExpr.setSubquery(false);
        }
        return queryBody.accept(this, tupSource);
    } else {
        LogicalVariable var = context.newVar();
        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(queryBody, tupSource);
        AssignOperator assignOp = new AssignOperator(var, new MutableObject<ILogicalExpression>(eo.first));
        assignOp.getInputs().add(eo.second);
        ProjectOperator projectOp = new ProjectOperator(var);
        projectOp.getInputs().add(new MutableObject<ILogicalOperator>(assignOp));
        return new Pair<>(projectOp, var);
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) 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) ProjectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)111 ArrayList (java.util.ArrayList)98 Mutable (org.apache.commons.lang3.mutable.Mutable)97 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)87 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)86 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)75 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)73 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)63 Pair (org.apache.hyracks.algebricks.common.utils.Pair)62 MutableObject (org.apache.commons.lang3.mutable.MutableObject)42 List (java.util.List)35 HashMap (java.util.HashMap)34 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)32 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)30 Collectors (java.util.stream.Collectors)29 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)29 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)29 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)27 HashSet (java.util.HashSet)25 File (java.io.File)24