Package org.apache.phoenix.schema

Examples of org.apache.phoenix.schema.PDataType.toObject()


    public static LiteralExpression getConstantExpression(Expression expression, ImmutableBytesWritable ptr)
            throws SQLException {
        Object value = null;
        PDataType type = expression.getDataType();
        if (expression.evaluate(null, ptr) && ptr.getLength() != 0) {
            value = type.toObject(ptr);
        }
        return LiteralExpression.newConstant(value, type, expression.isDeterministic());
    }

    public static boolean isNull(Expression expression, ImmutableBytesWritable ptr) {
View Full Code Here


        context = context == null ? "" : context;
        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
        assertTrue(expression.evaluate(null, ptr));
        PDataType dataType = expression.getDataType();
        SortOrder sortOrder = expression.getSortOrder();
        Object result = dataType.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), dataType, sortOrder);
        assertEquals(context, expectedResult, result);
    }
   
    private Expression getLiteral(Object value) throws Exception {
        return LiteralExpression.newConstant(value);
View Full Code Here

        Expression expression = getExpression();
        if (!expression.evaluate(tuple, ptr) || ptr.getLength() == 0) {
            return false;
        }
        PDataType type = expression.getDataType();
        String dateStr = (String)type.toObject(ptr, expression.getSortOrder());
        try {
            Object value = dateParser.parseObject(dateStr);
            byte[] byteValue = getDataType().toBytes(value);
            ptr.set(byteValue);
            return true;
View Full Code Here

    @Override
    public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) {
        if (tuple instanceof SingleKeyValueTuple) {
            // Case when scanners do look ahead and re-aggregate result row.The result is already available in the ptr
            PDataType resultDataType = getResultDataType();
            cachedResult = resultDataType.toObject(ptr, resultDataType, sortOrder);
        } else {
            InputStream is = new ByteArrayInputStream(ptr.get(), ptr.getOffset() + 1, ptr.getLength() - 1);
            try {
                if (Bytes.equals(ptr.get(), ptr.getOffset(), 1, DistinctValueWithCountServerAggregator.COMPRESS_MARKER,
                        0, 1)) {
View Full Code Here

            // We could potentially not invert the bytes, but we might as well since we're allocating
            // additional space here anyway.
            if (childType.isCoercibleTo(PDataType.VARCHAR)) {
                result = ByteUtil.concat(result, ByteUtil.concat(sortOrder, ptr));
            } else {
                result = ByteUtil.concat(result, PDataType.VARCHAR.toBytes(childType.toObject(ptr, sortOrder).toString()));
            }
        }
        ptr.set(result);
        return true;
    }
View Full Code Here

        if (ptr.getLength() == 0) {
            throw new IllegalDataException(getMissingEncodeFormatMsg());
        }

        PDataType type = encodingExpression.getDataType();
        String encodingFormat = ((String) type.toObject(ptr)).toUpperCase();
        EncodeFormat format = EncodeFormat.valueOf(encodingFormat);
        switch (format) {
            case BASE62:
                String encodedString = Base62Encoder.toString(num);
                ptr.set(PDataType.VARCHAR.toBytes(encodedString));
View Full Code Here

    if (ptr.getLength() == 0) {
      return true; // expression was evaluated, but evaluated to null
    }

    PDataType type = expression.getDataType();
    String stringToDecode = (String) type.toObject(ptr);

    Expression encodingExpression = getEncodingExpression();
    if (!encodingExpression.evaluate(tuple, ptr)) {
      return false;
    }
View Full Code Here

    if (ptr.getLength() == 0) {
      throw new IllegalDataException("Missing bytes encoding.");
    }

    type = encodingExpression.getDataType();
    String encoding = ((String) type.toObject(ptr)).toUpperCase();

    byte out[];

    EncodeFormat format = EncodeFormat.valueOf(encoding);
    switch (format) {
View Full Code Here

        Expression expression = getExpression();
        if (!expression.evaluate(tuple, ptr)) {
            return false;
        }
        PDataType type = expression.getDataType();
        Object value = formatter.format(type.toObject(ptr, expression.getSortOrder()));
        byte[] b = getDataType().toBytes(value);
        ptr.set(b);
        return true;
     }
View Full Code Here

            return true;
        }

        PDataType type = expression.getDataType();
        if (type.isCoercibleTo(PDataType.TIMESTAMP)) {
          Date date = (Date) type.toObject(ptr, expression.getSortOrder());
          BigDecimal time = new BigDecimal(date.getTime());
            byte[] byteValue = getDataType().toBytes(time);
            ptr.set(byteValue);
            return true;
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.