Search in sources :

Example 56 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class PushAggregateIntoNestedSubplanRule method collectOneVarPerAggFromOpWithNestedPlans.

private List<LogicalVariable> collectOneVarPerAggFromOpWithNestedPlans(AbstractOperatorWithNestedPlans op) {
    List<ILogicalPlan> nPlans = op.getNestedPlans();
    if (nPlans == null || nPlans.isEmpty()) {
        return Collections.emptyList();
    }
    List<LogicalVariable> aggVars = new ArrayList<>();
    // test that the operator computes a "listify" aggregate
    for (int i = 0; i < nPlans.size(); i++) {
        AbstractLogicalOperator topOp = (AbstractLogicalOperator) nPlans.get(i).getRoots().get(0).getValue();
        if (topOp.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
            continue;
        }
        AggregateOperator agg = (AggregateOperator) topOp;
        if (agg.getVariables().size() != 1) {
            continue;
        }
        ILogicalExpression expr = agg.getExpressions().get(0).getValue();
        if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
            continue;
        }
        AbstractFunctionCallExpression fceAgg = (AbstractFunctionCallExpression) expr;
        if (fceAgg.getFunctionIdentifier() != BuiltinFunctions.LISTIFY) {
            continue;
        }
        aggVars.add(agg.getVariables().get(0));
    }
    return aggVars;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)

Example 57 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class AsterixIntroduceGroupByCombinerRule method processNullTest.

@SuppressWarnings("unchecked")
@Override
protected void processNullTest(IOptimizationContext context, GroupByOperator nestedGby, List<LogicalVariable> aggregateVarsProducedByCombiner) {
    IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(BuiltinFunctions.IS_SYSTEM_NULL);
    SelectOperator selectNonSystemNull;
    if (aggregateVarsProducedByCombiner.size() == 1) {
        ILogicalExpression isSystemNullTest = new ScalarFunctionCallExpression(finfoEq, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(aggregateVarsProducedByCombiner.get(0))));
        IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
        ScalarFunctionCallExpression nonSystemNullTest = new ScalarFunctionCallExpression(finfoNot, new MutableObject<ILogicalExpression>(isSystemNullTest));
        selectNonSystemNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonSystemNullTest), false, null);
    } else {
        List<Mutable<ILogicalExpression>> isSystemNullTestList = new ArrayList<Mutable<ILogicalExpression>>();
        for (LogicalVariable aggVar : aggregateVarsProducedByCombiner) {
            ILogicalExpression isSystemNullTest = new ScalarFunctionCallExpression(finfoEq, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(aggVar)));
            IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
            ScalarFunctionCallExpression nonSystemNullTest = new ScalarFunctionCallExpression(finfoNot, new MutableObject<ILogicalExpression>(isSystemNullTest));
            isSystemNullTestList.add(new MutableObject<ILogicalExpression>(nonSystemNullTest));
        }
        IFunctionInfo finfoAnd = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND);
        selectNonSystemNull = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(finfoAnd, isSystemNullTestList)), false, null);
    }
    //add the not-system-null check into the nested pipeline
    Mutable<ILogicalOperator> ntsBeforeNestedGby = nestedGby.getInputs().get(0);
    nestedGby.getInputs().set(0, new MutableObject<ILogicalOperator>(selectNonSystemNull));
    selectNonSystemNull.getInputs().add(ntsBeforeNestedGby);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) SelectOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 58 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class IntroduceEnforcedListTypeRule method rewriteExpressions.

private boolean rewriteExpressions(List<Mutable<ILogicalExpression>> expressions, IVariableTypeEnvironment env) throws AlgebricksException {
    boolean changed = false;
    for (Mutable<ILogicalExpression> exprRef : expressions) {
        ILogicalExpression expr = exprRef.getValue();
        if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
            AbstractFunctionCallExpression argFuncExpr = (AbstractFunctionCallExpression) expr;
            IAType exprType = (IAType) env.getType(argFuncExpr);
            if (StaticTypeCastUtil.rewriteListExpr(argFuncExpr, exprType, exprType, env)) {
                TypeCastUtils.resetRequiredAndInputTypes(argFuncExpr);
                changed = true;
            }
        }
    }
    return changed;
}
Also used : ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) IAType(org.apache.asterix.om.types.IAType)

Example 59 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class IntroduceMaterializationForInsertWithSelfScanRule method checkIfInsertAndScanDatasetsSame.

private boolean checkIfInsertAndScanDatasetsSame(AbstractLogicalOperator op, String insertDatasetName) {
    boolean sameDataset = false;
    for (int i = 0; i < op.getInputs().size(); ++i) {
        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
        if (descendantOp.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
            UnnestMapOperator unnestMapOp = (UnnestMapOperator) descendantOp;
            ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
            if (unnestExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
                AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) unnestExpr;
                FunctionIdentifier fid = f.getFunctionIdentifier();
                if (!fid.equals(BuiltinFunctions.INDEX_SEARCH)) {
                    throw new IllegalStateException();
                }
                AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
                jobGenParams.readFromFuncArgs(f.getArguments());
                boolean isPrimaryIndex = jobGenParams.isPrimaryIndex();
                String indexName = jobGenParams.getIndexName();
                if (isPrimaryIndex && indexName.compareTo(insertDatasetName) == 0) {
                    return true;
                }
            }
        } else if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
            DataSourceScanOperator dataSourceScanOp = (DataSourceScanOperator) descendantOp;
            DataSource ds = (DataSource) dataSourceScanOp.getDataSource();
            if ((ds.getDatasourceType() == Type.INTERNAL_DATASET || ds.getDatasourceType() == Type.EXTERNAL_DATASET) && ((DatasetDataSource) ds).getDataset().getDatasetName().compareTo(insertDatasetName) == 0) {
                return true;
            }
        }
        sameDataset = checkIfInsertAndScanDatasetsSame(descendantOp, insertDatasetName);
        if (sameDataset) {
            break;
        }
    }
    return sameDataset;
}
Also used : FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) AccessMethodJobGenParams(org.apache.asterix.optimizer.rules.am.AccessMethodJobGenParams) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator) UnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) DataSource(org.apache.asterix.metadata.declared.DataSource) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource)

Example 60 with ILogicalExpression

use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.

the class LoadRecordFieldsRule method findFieldByNameFromRecordConstructor.

// Resolves field expression by name-based access.
private static ILogicalExpression findFieldByNameFromRecordConstructor(Object fldName, AbstractFunctionCallExpression fce) {
    Iterator<Mutable<ILogicalExpression>> fldIter = fce.getArguments().iterator();
    while (fldIter.hasNext()) {
        ILogicalExpression fldExpr = fldIter.next().getValue();
        if (fldName.equals(ConstantExpressionUtil.getStringConstant(fldExpr))) {
            return fldIter.next().getValue();
        }
        fldIter.next();
    }
    return null;
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)

Aggregations

ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)312 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)182 Mutable (org.apache.commons.lang3.mutable.Mutable)160 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)130 ArrayList (java.util.ArrayList)125 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)125 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)121 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)84 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)75 Pair (org.apache.hyracks.algebricks.common.utils.Pair)70 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)68 MutableObject (org.apache.commons.lang3.mutable.MutableObject)62 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)50 IAType (org.apache.asterix.om.types.IAType)42 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)38 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)36 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)34 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)34 HashSet (java.util.HashSet)32 AString (org.apache.asterix.om.base.AString)32