Package org.apache.pig.newplan.logical.expression

Examples of org.apache.pig.newplan.logical.expression.ConstantExpression


    {
        if(op == null) {
            return null;
        }
        if(op instanceof ConstantExpression) {
            ConstantExpression constExpr =(ConstantExpression)op ;
            return new Expression.Const( constExpr.getValue() );
        } else if (op instanceof ProjectExpression) {
            ProjectExpression projExpr = (ProjectExpression)op;
            String fieldName = projExpr.getFieldSchema().alias;
            return new Expression.Column(fieldName);
        } else {
View Full Code Here


    {
        if(op == null) {
            return null;
        }
        if(op instanceof ConstantExpression) {
            ConstantExpression constExpr =(ConstantExpression)op ;
            return new Expression.Const( constExpr.getValue() );
        } else if (op instanceof ProjectExpression) {
            ProjectExpression projExpr = (ProjectExpression)op;
            String fieldName = projExpr.getFieldSchema().alias;
            return new Expression.Column(fieldName);
        } else if(op instanceof BinaryExpression) {
View Full Code Here

                        throw new FrontendException(e);
                    }
                    valSet = true;
                }
                if (valSet) {
                    ConstantExpression constantExpr;
                    constantExpr = new ConstantExpression(currentWalker.getPlan(), val);
                    constantExpr.inheritSchema(op);
                    currentWalker.getPlan().replace(op, constantExpr);
                }
            }
View Full Code Here

            SourceLocation valLoc)
                    throws ParserValidationException {

        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        //  Generate a filter condition.
        LogicalExpression konst = new ConstantExpression( filterPlan, value);
        konst.setLocation( valLoc );
        UserFuncExpression udf = new UserFuncExpression( filterPlan, new FuncSpec( RANDOM.class.getName() ) );
        new LessThanExpression( filterPlan, udf, konst );
        LOFilter filter = new LOFilter( plan, true );
        return buildFilterOp( loc, filter, alias, inputAlias, filterPlan );
    }
View Full Code Here

            LogicalExpressionPlan exprPlan)
            throws ParserValidationException {
        try {
            filterOp.setAlias(inputAlias);
            List<LogicalExpression> args = new ArrayList<LogicalExpression>();
            ConstantExpression lhs = new ConstantExpression(exprPlan, new Boolean(true));
            ConstantExpression rhs = new ConstantExpression(exprPlan, new Boolean(false));
            BinCondExpression binCond = new BinCondExpression(exprPlan, expr, lhs, rhs);
            args.add(binCond);
            ConstantExpression constExpr = new ConstantExpression(exprPlan, (comment == null ? "" : comment));
            args.add(constExpr);
            UserFuncExpression udf = new UserFuncExpression(exprPlan, new FuncSpec( Assert.class.getName() ), args );
            exprPlan.add(udf);
            filterOp.setFilterPlan(exprPlan);
            // pass the inputAlias to alias
View Full Code Here

        private Object getNULLConstantInCast(LogicalExpression rel) throws FrontendException {
            if(rel instanceof CastExpression){
                if( ((CastExpression)rel).getExpression() instanceof CastExpression)
                    return getNULLConstantInCast(((CastExpression)rel).getExpression());
                else if( ((CastExpression)rel).getExpression() instanceof ConstantExpression){
                    ConstantExpression constExp = (ConstantExpression)((CastExpression)rel).getExpression();
                    if(constExp.getValue() == null)
                        return constExp;
                    else
                        return null;
                }
            }
View Full Code Here

        plan.connect(op, splitOp);
        for (Operator suc : sucs) {
            // position is remembered in order to maintain the order of the successors
            Pair<Integer, Integer> pos = plan.disconnect(op, suc);
            LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
            new ConstantExpression(filterPlan, Boolean.valueOf(true));
            LOSplitOutput splitOutput = new LOSplitOutput((LogicalPlan) plan, filterPlan);
            splitOutput.setAlias(splitOp.getAlias());
            plan.add(splitOutput);
            plan.connect(splitOp, splitOutput);
            plan.connect(splitOutput, pos.first, suc, pos.second);
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private void binaryExpressionConstPrune(LogicalExpression parent)
                    throws FrontendException {
        ConstantExpression rhs = result.pop(), lhs = result.pop();
        if (rhs == null || lhs == null) {
            result.push(null);
        }
        else {
            ConstantExpression newExp = null;
            if (parent instanceof AndExpression) newExp = new ConstantExpression(
                            plan,
                            (Boolean) rhs.getValue() && (Boolean) lhs.getValue());
            else if (parent instanceof OrExpression) newExp = new ConstantExpression(
                            plan,
                            (Boolean) rhs.getValue() || (Boolean) lhs.getValue());
            else if (parent instanceof EqualExpression) newExp = new ConstantExpression(
                            plan, rhs.isEqual(lhs));
            else if (parent instanceof GreaterThanExpression) newExp = new ConstantExpression(
                            plan,
                            ((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) > 0);
            else if (parent instanceof GreaterThanEqualExpression) newExp = new ConstantExpression(
                            plan,
                            ((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) >= 0);
            else if (parent instanceof LessThanExpression) newExp = new ConstantExpression(
                            plan,
                            ((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) < 0);
            else if (parent instanceof LessThanExpression) newExp = new ConstantExpression(
                            plan,
                            ((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) <= 0);
            else if (parent instanceof AddExpression) {
                byte type = parent.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Integer) lhs.getValue() + (Integer) rhs.getValue());
                        break;
                    case DataType.LONG:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Long) lhs.getValue() + (Long) rhs.getValue());
                        break;
                    case DataType.FLOAT:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Float) lhs.getValue() + (Float) rhs.getValue());
                        break;
                    case DataType.DOUBLE:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Double) lhs.getValue() + (Double) rhs.getValue());
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) lhs.getValue()).add((BigInteger) rhs.getValue()));
                        break;
                    case DataType.BIGDECIMAL:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigDecimal) lhs.getValue()).add((BigDecimal) rhs.getValue()));
                        break;
                    default:
                        throw new FrontendException("Invalid type");
                }
            }
            else if (parent instanceof SubtractExpression) {
                byte type = parent.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Integer) lhs.getValue() - (Integer) rhs.getValue());
                        break;
                    case DataType.LONG:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Long) lhs.getValue() - (Long) rhs.getValue());
                        break;
                    case DataType.FLOAT:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Float) lhs.getValue() - (Float) rhs.getValue());
                        break;
                    case DataType.DOUBLE:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Double) lhs.getValue() - (Double) rhs.getValue());
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) lhs.getValue()).subtract((BigInteger) rhs.getValue()));
                        break;
                    case DataType.BIGDECIMAL:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigDecimal) lhs.getValue()).subtract((BigDecimal) rhs.getValue()));
                        break;
                    default:
                        throw new FrontendException("Invalid type");
                }
            }
            else if (parent instanceof MultiplyExpression) {
                byte type = parent.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Integer) lhs.getValue() * (Integer) rhs.getValue());
                        break;
                    case DataType.LONG:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Long) lhs.getValue() * (Long) rhs.getValue());
                        break;
                    case DataType.FLOAT:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Float) lhs.getValue() * (Float) rhs.getValue());
                        break;
                    case DataType.DOUBLE:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Double) lhs.getValue() * (Double) rhs.getValue());
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) lhs.getValue()).multiply((BigInteger) rhs.getValue()));
                        break;
                    case DataType.BIGDECIMAL:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigDecimal) lhs.getValue()).multiply((BigDecimal) rhs.getValue()));
                        break;
                    default:
                        throw new FrontendException("Invalid type");
                }
            }
            else if (parent instanceof ModExpression) {
                byte type = parent.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Integer) lhs.getValue() % (Integer) rhs.getValue());
                        break;
                    case DataType.LONG:
                        newExp = new ConstantExpression(
                                        plan,
                                        (Long) lhs.getValue() % (Long) rhs.getValue());
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) lhs.getValue()).mod((BigInteger) rhs.getValue()));
                        break;
                    default:
                        throw new FrontendException("Invalid type");
                }
            }
            else if (parent instanceof DivideExpression) {
                byte type = parent.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        if ((Integer) rhs.getValue() != 0)
                            newExp = new ConstantExpression(
                                            plan,
                                            (Integer) lhs.getValue() / (Integer) rhs.getValue());
                        break;
                    case DataType.LONG:
                        if ((Long) rhs.getValue() != 0)
                            newExp = new ConstantExpression(
                                            plan,
                                            (Long) lhs.getValue() / (Long) rhs.getValue());
                        break;
                    case DataType.FLOAT:
                        if ((Float) rhs.getValue() != 0)
                            newExp = new ConstantExpression(
                                            plan,
                                            (Float) lhs.getValue() / (Float) rhs.getValue());
                        break;
                    case DataType.DOUBLE:
                        if ((Double) rhs.getValue() != 0)
                            newExp = new ConstantExpression(
                                            plan,
                                            (Double) lhs.getValue() / (Double) rhs.getValue());
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) lhs.getValue()).divide((BigInteger) rhs.getValue()));
                        break;
                    case DataType.BIGDECIMAL:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigDecimal) lhs.getValue()).divide((BigDecimal) rhs.getValue()));
                        break;
                    default:
                        throw new FrontendException("Invalid type");
View Full Code Here

        }
    }

    private void unaryExpressionConstPrune(LogicalExpression op)
                    throws FrontendException {
        ConstantExpression operand = result.pop();
        if (operand == null) {
            result.push(null);
            return;
        }
        if (op instanceof CastExpression) {
            // no simplification on cast for now
            result.push(null);
        }
        else {
            plan.remove(operand);
            plan.remove(op);
            ConstantExpression newExp;
            if (op instanceof NotExpression) newExp = new ConstantExpression(
                            plan, !((Boolean) operand.getValue()));
            else if (op instanceof IsNullExpression) newExp = new ConstantExpression(
                            plan, operand.getValue() == null);
            else if (op instanceof NegativeExpression) {
                byte type = operand.getFieldSchema().type;
                switch (type) {
                    case DataType.INTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        -1 * ((Integer) operand.getValue()));
                        break;
                    case DataType.LONG:
                        newExp = new ConstantExpression(
                                        plan,
                                        -1L * ((Long) operand.getValue()));
                        break;
                    case DataType.FLOAT:
                        newExp = new ConstantExpression(
                                        plan,
                                        -1.0F * ((Float) operand.getValue()));
                        break;
                    case DataType.DOUBLE:
                        newExp = new ConstantExpression(
                                        plan,
                                        -1.0D * ((Integer) operand.getValue()));
                        break;
                    case DataType.BIGINTEGER:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigInteger) operand.getValue()).negate());
                        break;
                    case DataType.BIGDECIMAL:
                        newExp = new ConstantExpression(
                                        plan,
                                        ((BigDecimal) operand.getValue()).negate());
                        break;
                    default:
                        throw new FrontendException("Invalid type");
View Full Code Here

            SourceLocation valLoc)
                    throws ParserValidationException {

        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        //  Generate a filter condition.
        LogicalExpression konst = new ConstantExpression( filterPlan, value);
        konst.setLocation( valLoc );
        UserFuncExpression udf = new UserFuncExpression( filterPlan, new FuncSpec( RANDOM.class.getName() ) );
        new LessThanExpression( filterPlan, udf, konst );
        LOFilter filter = new LOFilter( plan, true );
        return buildFilterOp( loc, filter, alias, inputAlias, filterPlan );
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.newplan.logical.expression.ConstantExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.