Package org.apache.phoenix.schema

Examples of org.apache.phoenix.schema.PDataType


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (isNullable() ? 1231 : 1237);
        PDataType type = this.getDataType();
        result = prime * result + ((type == null) ? 0 : type.hashCode());
        return result;
    }
View Full Code Here


            if (childNodeFixedLength != null && key.length > childNodeFixedLength) {
                return DEGENERATE_KEY_PARTS;
            }
            // TODO: is there a case where we'd need to go through the childPart to calculate the key range?
            PColumn column = childSlot.getKeyPart().getColumn();
            PDataType type = column.getDataType();
            byte[] lowerRange = key;
            byte[] upperRange = ByteUtil.nextKey(key);
            Integer columnFixedLength = column.getMaxLength();
            if (type.isFixedWidth() && columnFixedLength != null) {
                lowerRange = StringUtil.padChar(lowerRange, columnFixedLength);
                upperRange = StringUtil.padChar(upperRange, columnFixedLength);
            }
            KeyRange keyRange = type.getKeyRange(lowerRange, true, upperRange, false);
            // Only extract LIKE expression if pattern ends with a wildcard and everything else was extracted
            return newKeyParts(childSlot, node.endsWithOnlyWildcard() ? node : null, keyRange);
        }
View Full Code Here

                return null;
            }
            KeySlots childSlots = childParts.get(0);
            KeySlot childSlot = childSlots.iterator().next();
            PColumn column = childSlot.getKeyPart().getColumn();
            PDataType type = column.getDataType();
            boolean isFixedWidth = type.isFixedWidth();
            if (isFixedWidth) { // if column can't be null
                return node.isNegate() ? null :
                    newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true,
                                                                  KeyRange.UNBOUND, true));
            } else {
                KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE;
                return newKeyParts(childSlot, node, keyRange);
            }
View Full Code Here

    public CaseExpression() {
    }
   
    private static List<Expression> coerceIfNecessary(List<Expression> children) throws SQLException {
        boolean isChildTypeUnknown = false;
        PDataType returnType = children.get(0).getDataType();
        for (int i = 2; i < children.size(); i+=2) {
            Expression child = children.get(i);
            PDataType childType = child.getDataType();
            if (childType == null) {
                isChildTypeUnknown = true;
            } else if (returnType == null) {
                returnType = childType;
                isChildTypeUnknown = true;
            } else if (returnType == childType || childType.isCoercibleTo(returnType)) {
                continue;
            } else if (returnType.isCoercibleTo(childType)) {
                returnType = childType;
            } else {
                throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CONVERT_TYPE)
                    .setMessage("Case expressions must have common type: " + returnType + " cannot be coerced to " + childType)
                    .build().buildException();
            }
        }
        // If we found an "unknown" child type and the return type is a number
        // make the return type be the most general number type of DECIMAL.
        if (isChildTypeUnknown && returnType != null && returnType.isCoercibleTo(PDataType.DECIMAL)) {
            returnType = PDataType.DECIMAL;
        }
        List<Expression> newChildren = children;
        for (int i = 0; i < children.size(); i+=2) {
            Expression child = children.get(i);
            PDataType childType = child.getDataType();
            if (childType != returnType) {
                if (newChildren == children) {
                    newChildren = new ArrayList<Expression>(children);
                }
                newChildren.set(i, CoerceExpression.create(child, returnType));
View Full Code Here

        return "";
    }

    @Override
    public String getColumnClassName(int column) throws SQLException {
        PDataType type = rowProjector.getColumnProjector(column-1).getExpression().getDataType();
        return type == null ? null : type.getJavaClassName();
    }
View Full Code Here

    @Override
    public int getColumnDisplaySize(int column) throws SQLException {
        ColumnProjector projector = rowProjector.getColumnProjector(column-1);
        int displaySize = Math.max(projector.getName().length(),MIN_DISPLAY_WIDTH);
        PDataType type = projector.getExpression().getDataType();
        if (type == null) {
            return Math.min(Math.max(displaySize, QueryConstants.NULL_DISPLAY_TEXT.length()), MAX_DISPLAY_WIDTH);
        }
        if (type.isCoercibleTo(PDataType.DATE)) {
            return Math.min(Math.max(displaySize, connection.getDatePattern().length()), MAX_DISPLAY_WIDTH);
        }
        if (type.isFixedWidth() && projector.getExpression().getMaxLength() != null) {
            return Math.min(Math.max(displaySize, projector.getExpression().getMaxLength()), MAX_DISPLAY_WIDTH);
        }
       
        return Math.min(Math.max(displaySize, DEFAULT_DISPLAY_WIDTH), MAX_DISPLAY_WIDTH);
    }
View Full Code Here

            @Override
            public KeyRange getKeyRange(CompareOp op, Expression rhs) {
                ImmutableBytesWritable ptr = new ImmutableBytesWritable();
                rhs.evaluate(null, ptr);
                // If the column is fixed width, fill is up to it's byte size
                PDataType type = getColumn().getDataType();
                if (type.isFixedWidth()) {
                    Integer length = getColumn().getMaxLength();
                    if (length != null) {
                        // Go through type to pad as the fill character depends on the type.
                        type.pad(ptr, length);
                    }
                }
                byte[] key = ByteUtil.copyKeyBytesIfNecessary(ptr);
                return ByteUtil.getKeyRange(key, op, type);
            }
View Full Code Here

        return rowProjector.getColumnProjector(column-1).getName();
    }

    @Override
    public int getColumnType(int column) throws SQLException {
        PDataType type = rowProjector.getColumnProjector(column-1).getExpression().getDataType();
        return type == null ? Types.NULL : type.getResultSetSqlType();
    }
View Full Code Here

        return type == null ? Types.NULL : type.getResultSetSqlType();
    }

    @Override
    public String getColumnTypeName(int column) throws SQLException {
        PDataType type = rowProjector.getColumnProjector(column-1).getExpression().getDataType();
        return type == null ? null : type.getSqlTypeName();
    }
View Full Code Here

        return true;
    }

    @Override
    public boolean isSigned(int column) throws SQLException {
        PDataType type = rowProjector.getColumnProjector(column-1).getExpression().getDataType();
        if (type == null) {
            return false;
        }
        return type.isCoercibleTo(PDataType.DECIMAL);
    }
View Full Code Here

TOP

Related Classes of org.apache.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.