Package com.salesforce.phoenix.schema

Examples of com.salesforce.phoenix.schema.PDataType


        super(name, children, info);
    }

    @Override
    public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
        PDataType dataType = children.get(0).getDataType();
        String formatString = (String)((LiteralExpression)children.get(1)).getValue(); // either date or number format string
        Format formatter;
        FunctionArgumentType type;
        if (dataType.isCoercibleTo(PDataType.TIMESTAMP)) {
            if (formatString == null) {
                formatString = context.getDateFormat();
                formatter = context.getDateFormatter();
            } else {
                formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
            }
            type = FunctionArgumentType.TEMPORAL;
        }
        else if (dataType.isCoercibleTo(PDataType.DECIMAL)) {
            if (formatString == null)
                formatString = context.getNumberFormat();
            formatter = FunctionArgumentType.NUMERIC.getFormatter(formatString);
            type = FunctionArgumentType.NUMERIC;
        }
View Full Code Here


            }
            if (ptr.getLength() == 0) {
                return true;
            }
           
            PDataType childType = childExpr.getDataType();
            boolean isDate = childType.isCoercibleTo(PDataType.DATE);
            ColumnModifier childColumnModifier = childExpr.getColumnModifier();
            BigDecimal bd = isDate ?
                    BigDecimal.valueOf(childType.getCodec().decodeLong(ptr, childColumnModifier)) :
                    (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childColumnModifier);
           
            if (result == null) {
                result = bd;
            } else {
View Full Code Here

            }
            if (ptr.getLength() == 0) {
                return true;
            }
            long value;
            PDataType type = children.get(i).getDataType();
            ColumnModifier columnModifier = children.get(i).getColumnModifier();
            if (type == PDataType.DECIMAL) {
                BigDecimal bd = (BigDecimal)PDataType.DECIMAL.toObject(ptr, columnModifier);
                value = bd.multiply(BD_MILLIS_IN_DAY).longValue();
            } else if (type.isCoercibleTo(PDataType.LONG)) {
                value = type.getCodec().decodeLong(ptr, columnModifier) * QueryConstants.MILLIS_IN_DAY;
            } else if (type.isCoercibleTo(PDataType.DOUBLE)) {
                value = (long)(type.getCodec().decodeDouble(ptr, columnModifier) * QueryConstants.MILLIS_IN_DAY);
            } else {
                value = type.getCodec().decodeLong(ptr, columnModifier);
            }
            finalResult += value;
        }
        byte[] resultPtr = new byte[getDataType().getByteSize()];
        ptr.set(resultPtr);
View Full Code Here

            return isDeterministic ? TRUE_EXPRESSION : ND_TRUE_EXPRESSION;
        }
        if (value == null) {
            return isDeterministic ? NULL_EXPRESSION : ND_NULL_EXPRESSION;
        }
        PDataType type = PDataType.fromLiteral(value);
        byte[] b = type.toBytes(value);
        if (b.length == 0) {
            return TYPED_NULL_EXPRESSIONS[type.ordinal() + ( isDeterministic ? 0 : TYPED_NULL_EXPRESSIONS.length/2)];
        }
        if (type == PDataType.VARCHAR) {
            String s = (String) value;
            if (s.length() == b.length) { // single byte characters only
                type = PDataType.CHAR;
View Full Code Here

            return isDeterministic ? FALSE_EXPRESSION : ND_FALSE_EXPRESSION;
        }
        if (Boolean.TRUE.equals(value)) {
            return isDeterministic ? TRUE_EXPRESSION : ND_TRUE_EXPRESSION;
        }
        PDataType actualType = PDataType.fromLiteral(value);
        // For array we should check individual element in it?
        // It would be costly though!!!!!
        if (!actualType.isCoercibleTo(type, value)) {
            throw TypeMismatchException.newException(type, actualType, value.toString());
        }
        value = type.toObject(value, actualType);
        try {
            byte[] b = type.toBytes(value, columnModifier);
View Full Code Here

            }
            if (ptr.getLength() == 0) {
                return true;
            }
           
            PDataType childType = childExpr.getDataType();
            ColumnModifier childColumnModifier = childExpr.getColumnModifier();
            BigDecimal bd= (BigDecimal)PDataType.DECIMAL.toObject(ptr, childType, childColumnModifier);
           
            if (result == null) {
                result = bd;
View Full Code Here

        return getRoundExpression(children);
    }

    public static Expression getRoundExpression(List<Expression> children) throws SQLException {
        final Expression firstChild = children.get(0);
        final PDataType firstChildDataType = firstChild.getDataType();
       
        if(firstChildDataType.isCoercibleTo(PDataType.DATE)) {
            return RoundDateExpression.create(children); // FIXME: remove cast
        } else if (firstChildDataType.isCoercibleTo(PDataType.TIMESTAMP)) {
            return RoundTimestampExpression.create(children); // FIXME: remove cast
        } else if(firstChildDataType.isCoercibleTo(PDataType.DECIMAL)) {
            return new RoundDecimalExpression(children);
        } else {
            throw TypeMismatchException.newException(firstChildDataType, "1");
        }
    }
View Full Code Here

        return getFloorExpression(children);
    }

    public static Expression getFloorExpression(List<Expression> children) throws SQLException {
        final Expression firstChild = children.get(0);
        final PDataType firstChildDataType = firstChild.getDataType();
       
        //FLOOR on timestamp doesn't really care about the nanos part i.e. it just sets it to zero.
        //Which is exactly what FloorDateExpression does too.
        if(firstChildDataType.isCoercibleTo(PDataType.TIMESTAMP)) {
            return FloorDateExpression.create(children);
        } else if(firstChildDataType.isCoercibleTo(PDataType.DECIMAL)) {
            return new FloorDecimalExpression(children);
        } else {
            throw TypeMismatchException.newException(firstChildDataType, "1");
        }
    }
View Full Code Here

        super(children);
    }
   
    public static Expression create(List<Expression> children) throws SQLException {
        Expression firstChild = children.get(0);
        PDataType firstChildDataType = firstChild.getDataType();
        if (firstChildDataType == PDataType.TIMESTAMP || firstChildDataType == PDataType.UNSIGNED_TIMESTAMP){
            // Coerce TIMESTAMP to DATE, as the nanos has no affect
            List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size());
            newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PDataType.TIMESTAMP ? PDataType.DATE : PDataType.UNSIGNED_DATE));
            newChildren.addAll(children.subList(1, children.size()));
View Full Code Here

        super(children);
    }
   
    public static Expression create (List<Expression> children) throws SQLException {
        Expression firstChild = children.get(0);
        PDataType firstChildDataType = firstChild.getDataType();
        String timeUnit = (String)((LiteralExpression)children.get(1)).getValue();
        LiteralExpression multiplierExpr = (LiteralExpression)children.get(2);
       
        /*
         * When rounding off timestamp to milliseconds, nanos play a part only when the multiplier value
View Full Code Here

TOP

Related Classes of com.salesforce.phoenix.schema.PDataType

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.