Search in sources :

Example 6 with PropagatingTypeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment in project asterixdb by apache.

the class LeftOuterUnnestMapOperator method computeOutputTypeEnvironment.

@Override
public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException {
    // Propagates all input variables that come from the outer branch.
    PropagatingTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx);
    env.getCorrelatedMissableVariableLists().add(variables);
    // of (original type + null).
    for (int i = 0; i < variables.size(); i++) {
        env.setVarType(variables.get(i), ctx.getMissableTypeComputer().makeMissableType(variableTypes.get(i)));
    }
    return env;
}
Also used : PropagatingTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment)

Example 7 with PropagatingTypeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment in project asterixdb by apache.

the class GroupByOperator method computeOutputTypeEnvironment.

@Override
public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException {
    int n = 0;
    for (ILogicalPlan p : nestedPlans) {
        n += p.getRoots().size();
    }
    ITypeEnvPointer[] envPointers = new ITypeEnvPointer[n];
    int i = 0;
    for (ILogicalPlan p : nestedPlans) {
        for (Mutable<ILogicalOperator> r : p.getRoots()) {
            envPointers[i] = new OpRefTypeEnvPointer(r, ctx);
            i++;
        }
    }
    IVariableTypeEnvironment env = new PropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMissableTypeComputer(), ctx.getMetadataProvider(), TypePropagationPolicy.ALL, envPointers);
    ILogicalOperator child = inputs.get(0).getValue();
    IVariableTypeEnvironment env2 = ctx.getOutputTypeEnvironment(child);
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : getGroupByList()) {
        ILogicalExpression expr = p.second.getValue();
        if (p.first != null) {
            env.setVarType(p.first, env2.getType(expr));
            if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                LogicalVariable v1 = ((VariableReferenceExpression) expr).getVariableReference();
                env.setVarType(v1, env2.getVarType(v1));
            }
        } else {
            VariableReferenceExpression vre = (VariableReferenceExpression) p.second.getValue();
            LogicalVariable v2 = vre.getVariableReference();
            env.setVarType(v2, env2.getVarType(v2));
        }
    }
    for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : getDecorList()) {
        ILogicalExpression expr = p.second.getValue();
        if (p.first != null) {
            env.setVarType(p.first, env2.getType(expr));
        } else {
            VariableReferenceExpression vre = (VariableReferenceExpression) p.second.getValue();
            LogicalVariable v2 = vre.getVariableReference();
            env.setVarType(v2, env2.getVarType(v2));
        }
    }
    return env;
}
Also used : PropagatingTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ILogicalPlan(org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan) OpRefTypeEnvPointer(org.apache.hyracks.algebricks.core.algebra.typing.OpRefTypeEnvPointer) ITypeEnvPointer(org.apache.hyracks.algebricks.core.algebra.typing.ITypeEnvPointer) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Example 8 with PropagatingTypeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment in project asterixdb by apache.

the class SelectOperator method computeOutputTypeEnvironment.

@Override
public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException {
    ITypeEnvPointer[] envPointers = new ITypeEnvPointer[1];
    envPointers[0] = new OpRefTypeEnvPointer(inputs.get(0), ctx);
    PropagatingTypeEnvironment env = new PropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMissableTypeComputer(), ctx.getMetadataProvider(), TypePropagationPolicy.ALL, envPointers);
    if (condition.getValue().getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        return env;
    }
    AbstractFunctionCallExpression f1 = (AbstractFunctionCallExpression) condition.getValue();
    if (!f1.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.NOT)) {
        return env;
    }
    ILogicalExpression a1 = f1.getArguments().get(0).getValue();
    if (a1.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
        AbstractFunctionCallExpression f2 = (AbstractFunctionCallExpression) a1;
        if (f2.getFunctionIdentifier().equals(AlgebricksBuiltinFunctions.IS_MISSING)) {
            ILogicalExpression a2 = f2.getArguments().get(0).getValue();
            if (a2.getExpressionTag() == LogicalExpressionTag.VARIABLE) {
                LogicalVariable var = ((VariableReferenceExpression) a2).getVariableReference();
                env.getNonNullVariables().add(var);
            }
        }
    }
    return env;
}
Also used : PropagatingTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) OpRefTypeEnvPointer(org.apache.hyracks.algebricks.core.algebra.typing.OpRefTypeEnvPointer) ITypeEnvPointer(org.apache.hyracks.algebricks.core.algebra.typing.ITypeEnvPointer)

Example 9 with PropagatingTypeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment in project asterixdb by apache.

the class LeftOuterUnnestOperator method computeOutputTypeEnvironment.

@Override
public IVariableTypeEnvironment computeOutputTypeEnvironment(ITypingContext ctx) throws AlgebricksException {
    PropagatingTypeEnvironment env = createPropagatingAllInputsTypeEnvironment(ctx);
    Object t = env.getType(expression.getValue());
    // For the variables from the inner branch, the output type is the union
    // of (original type + missing).
    env.setVarType(variables.get(0), ctx.getMissableTypeComputer().makeMissableType(t));
    if (positionalVariable != null) {
        env.setVarType(positionalVariable, ctx.getMissableTypeComputer().makeMissableType(positionalVariableType));
    }
    // The produced variables of the this operator are missable because of the left outer semantics.
    List<LogicalVariable> missableVars = new ArrayList<>();
    missableVars.add(variables.get(0));
    if (positionalVariable != null) {
        missableVars.add(positionalVariable);
    }
    env.getCorrelatedMissableVariableLists().add(missableVars);
    return env;
}
Also used : PropagatingTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment) LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ArrayList(java.util.ArrayList)

Example 10 with PropagatingTypeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment in project asterixdb by apache.

the class NestedTupleSourceOperator method computeOutputTypeEnvironment.

@Override
public IVariableTypeEnvironment computeOutputTypeEnvironment(final ITypingContext ctx) throws AlgebricksException {
    ITypeEnvPointer[] p = new ITypeEnvPointer[1];
    p[0] = new ITypeEnvPointer() {

        @Override
        public IVariableTypeEnvironment getTypeEnv() {
            ILogicalOperator op = dataSourceReference.getValue().getInputs().get(0).getValue();
            return ctx.getOutputTypeEnvironment(op);
        }
    };
    return new PropagatingTypeEnvironment(ctx.getExpressionTypeComputer(), ctx.getMissableTypeComputer(), ctx.getMetadataProvider(), TypePropagationPolicy.ALL, p);
}
Also used : PropagatingTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ITypeEnvPointer(org.apache.hyracks.algebricks.core.algebra.typing.ITypeEnvPointer) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Aggregations

PropagatingTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.typing.PropagatingTypeEnvironment)10 ITypeEnvPointer (org.apache.hyracks.algebricks.core.algebra.typing.ITypeEnvPointer)7 OpRefTypeEnvPointer (org.apache.hyracks.algebricks.core.algebra.typing.OpRefTypeEnvPointer)6 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)5 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 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)2 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)2 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)2 Mutable (org.apache.commons.lang3.mutable.Mutable)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1