Search in sources :

Example 1 with IVariableEvalSizeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment in project asterixdb by apache.

the class LogicalPropertiesVisitor method visitAssignment.

private void visitAssignment(AbstractAssignOperator op, IOptimizationContext context) throws AlgebricksException {
    LogicalPropertiesVectorImpl v = propagateCardinality(op, context);
    if (v != null && v.getNumberOfTuples() != null) {
        IVariableEvalSizeEnvironment varSizeEnv = context.getVariableEvalSizeEnvironment();
        IExpressionEvalSizeComputer evalSize = context.getExpressionEvalSizeComputer();
        if (evalSize != null) {
            ILogicalOperator op0 = op.getInputs().get(0).getValue();
            ILogicalPropertiesVector v0 = context.getLogicalPropertiesVector(op0);
            if (v0 != null) {
                long frames0 = v0.getMaxOutputFrames();
                // added per tuple
                long overhead = 0;
                for (Mutable<ILogicalExpression> exprRef : op.getExpressions()) {
                    int sz = evalSize.getEvalSize(exprRef.getValue(), varSizeEnv);
                    if (sz == -1) {
                        return;
                    }
                    overhead += sz;
                }
                int frameSize = context.getPhysicalOptimizationConfig().getFrameSize();
                if (frameSize > 0) {
                    long sz = frames0 * frameSize + overhead * v.getNumberOfTuples();
                    int frames1 = (int) (sz / frameSize);
                    if (sz % frameSize > 0) {
                        frames1++;
                    }
                    v.setMaxOutputFrames(frames1);
                }
            }
        }
    }
}
Also used : IVariableEvalSizeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment) ILogicalPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) LogicalPropertiesVectorImpl(org.apache.hyracks.algebricks.core.algebra.properties.LogicalPropertiesVectorImpl) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) IExpressionEvalSizeComputer(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer)

Example 2 with IVariableEvalSizeEnvironment

use of org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment in project asterixdb by apache.

the class NonTaggedDataFormat method getExpressionEvalSizeComputer.

@Override
public IExpressionEvalSizeComputer getExpressionEvalSizeComputer() {
    return new IExpressionEvalSizeComputer() {

        @Override
        public int getEvalSize(ILogicalExpression expr, IVariableEvalSizeEnvironment env) throws AlgebricksException {
            switch(expr.getExpressionTag()) {
                case CONSTANT:
                    {
                        ConstantExpression c = (ConstantExpression) expr;
                        if (c == ConstantExpression.MISSING) {
                            return 1;
                        } else if (c == ConstantExpression.FALSE || c == ConstantExpression.TRUE) {
                            return 2;
                        } else {
                            AsterixConstantValue acv = (AsterixConstantValue) c.getValue();
                            IAObject o = acv.getObject();
                            switch(o.getType().getTypeTag()) {
                                case DOUBLE:
                                    return 9;
                                case FLOAT:
                                    return 5;
                                case BOOLEAN:
                                    return 2;
                                case MISSING:
                                    return 1;
                                case NULL:
                                    return 1;
                                case TINYINT:
                                    return 2;
                                case SMALLINT:
                                    return 3;
                                case INTEGER:
                                    return 5;
                                case BIGINT:
                                    return 9;
                                default:
                                    return -1;
                            }
                        }
                    }
                case FUNCTION_CALL:
                    {
                        AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
                        if (f.getFunctionIdentifier().equals(BuiltinFunctions.TID)) {
                            return 5;
                        } else {
                            // TODO
                            return -1;
                        }
                    }
                default:
                    {
                        // TODO
                        return -1;
                    }
            }
        }
    };
}
Also used : IVariableEvalSizeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) ConstantExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression) IAObject(org.apache.asterix.om.base.IAObject) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) IExpressionEvalSizeComputer(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer)

Aggregations

ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)2 IExpressionEvalSizeComputer (org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionEvalSizeComputer)2 IVariableEvalSizeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableEvalSizeEnvironment)2 IAObject (org.apache.asterix.om.base.IAObject)1 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)1 ILogicalPropertiesVector (org.apache.hyracks.algebricks.core.algebra.properties.ILogicalPropertiesVector)1 LogicalPropertiesVectorImpl (org.apache.hyracks.algebricks.core.algebra.properties.LogicalPropertiesVectorImpl)1