Package com.akiban.sql.types

Examples of com.akiban.sql.types.TypeId


     */
    public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType,
                                                         DataTypeDescriptor rightType,
                                                         String operator)
            throws StandardException {
        TypeId rightTypeId = rightType.getTypeId();
        boolean nullable = leftType.isNullable() || rightType.isNullable();
        if (rightTypeId.isDateTimeTimeStampTypeId()) {
            if (operator.equals(TypeCompiler.MINUS_OP)) {
                // TIMESTAMP - other datetime is INTERVAL DAY TO SECOND
                return new DataTypeDescriptor(TypeId.INTERVAL_DAY_SECOND_ID, nullable);
            }
        }
        else if (rightTypeId.isIntervalTypeId()) {
            if (operator.equals(TypeCompiler.PLUS_OP) ||
                operator.equals(TypeCompiler.MINUS_OP)) {
                // TIMESTAMP +/- interval is TIMESTAMP
                return leftType.getNullabilityType(nullable);
            }
View Full Code Here


     */
    public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType,
                                                         DataTypeDescriptor rightType,
                                                         String operator)
            throws StandardException {
        TypeId rightTypeId = rightType.getTypeId();
        boolean nullable = leftType.isNullable() || rightType.isNullable();
        if (rightTypeId.isDateTimeTimeStampTypeId()) {
            if (operator.equals(TypeCompiler.MINUS_OP)) {
                switch (rightTypeId.getTypeFormatId()) {
                case TypeId.FormatIds.TIME_TYPE_ID:
                    // TIME - TIME is INTERVAL HOUR TO SECOND
                    return new DataTypeDescriptor(TypeId.INTERVAL_HOUR_SECOND_ID, nullable);
                }
                // TIME - other datetime is INTERVAL DAY TO SECOND
                return new DataTypeDescriptor(TypeId.INTERVAL_DAY_SECOND_ID, nullable);
            }
        }
        else if (rightTypeId.isIntervalTypeId()) {
            if (operator.equals(TypeCompiler.PLUS_OP) ||
                operator.equals(TypeCompiler.MINUS_OP)) {
                switch (rightTypeId.getTypeFormatId()) {
                case TypeId.FormatIds.INTERVAL_DAY_SECOND_ID:
                    if ((rightTypeId == TypeId.INTERVAL_HOUR_ID) ||
                        (rightTypeId == TypeId.INTERVAL_MINUTE_ID) ||
                        (rightTypeId == TypeId.INTERVAL_SECOND_ID) ||
                        (rightTypeId == TypeId.INTERVAL_HOUR_MINUTE_ID) ||
View Full Code Here

        ** we call this method off the TypeId of the left operand, so if
        ** we get here, we know the left operand is a number.
        */
        assert leftType.getTypeId().isNumericTypeId() : "The left type is supposed to be a number because we're resolving an arithmetic operator";

        TypeId leftTypeId = leftType.getTypeId();
        TypeId rightTypeId = rightType.getTypeId();

        boolean supported = true;

        if (!(rightTypeId.isNumericTypeId())) {
            if (rightTypeId.isIntervalTypeId() &&
                operator.equals(TypeCompiler.TIMES_OP)) {
                // Let interval type resolve it.
                return getTypeCompiler(rightTypeId).resolveArithmeticOperation(rightType, leftType, operator);
            }
            supported = false;
        }

        if (TypeCompiler.MOD_OP.equals(operator)) {
            switch (leftTypeId.getJDBCTypeId()) {
            case java.sql.Types.TINYINT:
            case java.sql.Types.SMALLINT:
            case java.sql.Types.INTEGER:
            case java.sql.Types.BIGINT:
                break;
            default:
                supported = false;
                break;
            }
            switch (rightTypeId.getJDBCTypeId()) {
            case java.sql.Types.TINYINT:
            case java.sql.Types.SMALLINT:
            case java.sql.Types.INTEGER:
            case java.sql.Types.BIGINT:
                break;
            default:
                supported = false;
                break;
            }

        }

        if (!supported) {
            return super.resolveArithmeticOperation(leftType, rightType, operator);
        }

        /*
        ** Take left as the higher precedence if equal
        */
        if (rightTypeId.typePrecedence() > leftTypeId.typePrecedence()) {
            higherType = rightType;
            higherTC = (NumericTypeCompiler)getTypeCompiler(rightTypeId);
        }
        else {
            higherType = leftType;
View Full Code Here

            rightType = leftType.getNullabilityType(true);
            rightOperand.setType(rightType);
        }
        if ((leftType == null) || (rightType == null))
            return null;
        TypeId leftTypeId = leftType.getTypeId();
        TypeId rightTypeId = rightType.getTypeId();

        /* Do any implicit conversions from (long) (var)char. */
        if (leftTypeId.isStringTypeId() && rightTypeId.isNumericTypeId()) {
            boolean nullableResult;
            nullableResult = leftType.isNullable() || rightType.isNullable();

            /* If other side is decimal/numeric, then we need to diddle
             * with the precision, scale and max width in order to handle
             * computations like:    1.1 + '0.111'
             */
            int precision = rightType.getPrecision();
            int scale = rightType.getScale();
            int maxWidth = rightType.getMaximumWidth();

            if (rightTypeId.isDecimalTypeId()) {
                int charMaxWidth = leftType.getMaximumWidth();
                precision += (2 * charMaxWidth);
                scale += charMaxWidth;                             
                maxWidth = precision + 3;
            }

            leftOperand = (ValueNode)node.getNodeFactory()
                .getNode(NodeTypes.CAST_NODE,
                         leftOperand,
                         new DataTypeDescriptor(rightTypeId, precision,
                                                scale, nullableResult,
                                                maxWidth),
                         node.getParserContext());
            node.setLeftOperand(leftOperand);
        }
        else if (rightTypeId.isStringTypeId() && leftTypeId.isNumericTypeId()) {
            boolean nullableResult;
            nullableResult = leftType.isNullable() || rightType.isNullable();

            /* If other side is decimal/numeric, then we need to diddle
             * with the precision, scale and max width in order to handle
View Full Code Here

            if (leftType != null)
                rightOperand.setType(leftType.getNullabilityType(true));
        }
           

        TypeId leftTypeId = leftOperand.getTypeId();
        TypeId rightTypeId = rightOperand.getTypeId();

        if ((leftTypeId == null) || (rightTypeId == null))
            return null;

        /*
         * If we are comparing a non-string with a string type, then we
         * must prevent the non-string value from being used to probe into
         * an index on a string column. This is because the string types
         * are all of low precedence, so the comparison rules of the non-string
         * value are used, so it may not find values in a string index because
         * it will be in the wrong order.
         */
        if (!leftTypeId.isStringTypeId() && rightTypeId.isStringTypeId()) {
            DataTypeDescriptor leftType = leftOperand.getType();
            DataTypeDescriptor rightType = rightOperand.getType();

            rightOperand = (ValueNode)node.getNodeFactory()
                .getNode(NodeTypes.CAST_NODE,
                         rightOperand,
                         leftType.getNullabilityType(rightType.isNullable()),
                         node.getParserContext());
            node.setRightOperand(rightOperand);
        }
        else if (!rightTypeId.isStringTypeId() && leftTypeId.isStringTypeId()) {
            DataTypeDescriptor leftType = leftOperand.getType();
            DataTypeDescriptor rightType = rightOperand.getType();

            leftOperand = (ValueNode)node.getNodeFactory()
                .getNode(NodeTypes.CAST_NODE,
View Full Code Here

        }
        if (isParameterOrUntypedNull(highOperand)) {
            highOperand.setType(leftType.getNullabilityType(true));
        }

        TypeId leftTypeId = leftOperand.getTypeId();
        DataTypeDescriptor lowType = lowOperand.getType();
        DataTypeDescriptor highType = highOperand.getType();
        if (!leftTypeId.isStringTypeId()) {
            if ((lowType != null) && lowType.getTypeId().isStringTypeId()) {
                lowOperand = (ValueNode)node.getNodeFactory()
                    .getNode(NodeTypes.CAST_NODE,
                             lowOperand,
                             leftType.getNullabilityType(lowType.isNullable()),
View Full Code Here

    /**
     * @see TypeCompiler#getCastToCharWidth
     */
    public int getCastToCharWidth(DataTypeDescriptor dtd) {
        TypeId typeId = dtd.getTypeId();
        if (typeId == TypeId.INTERVAL_YEAR_ID) {
            return dtd.getPrecision(); // yyyy
        }
        else if (typeId == TypeId.INTERVAL_MONTH_ID) {
            return dtd.getPrecision(); // mmmm
View Full Code Here

     */
    public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType,
                                                         DataTypeDescriptor rightType,
                                                         String operator)
            throws StandardException {
        TypeId rightTypeId = rightType.getTypeId();
        TypeId leftTypeId = leftType.getTypeId();
        boolean nullable = leftType.isNullable() || rightType.isNullable();

        if (operator.equals(PLUS_OP) || operator.equals(MINUS_OP))
        {
            // date/time and interval
            TypeId datetimeType;
            if ((datetimeType = rightTypeId).isDateTimeTimeStampTypeId() && leftTypeId.isIntervalTypeId() ||
                  (datetimeType = leftTypeId).isDateTimeTimeStampTypeID() && rightTypeId.isIntervalTypeId())
                // Let specific datetime type resolve it.
                return getTypeCompiler(datetimeType).resolveArithmeticOperation(rightType, leftType, operator);
       
            // interval and interval
            int typeFormatId = 0;
            if (leftTypeId.isIntervalTypeId() && rightTypeId.isIntervalTypeId())
                // two intervals are exactly the same
                if (leftTypeId == rightTypeId)                   
                    return leftType.getNullabilityType(nullable);
                // two intervals are of the same *type*
                else if ((typeFormatId = leftTypeId.getTypeFormatId()) == rightTypeId.getTypeFormatId())
                    return new DataTypeDescriptor(typeFormatId == TypeId.FormatIds.INTERVAL_DAY_SECOND_ID ?
                                                    TypeId.INTERVAL_SECOND_ID : TypeId.INTERVAL_MONTH_ID,
                                                    nullable);
                       
            // varchar
             DataTypeDescriptor varcharType;
             if ((varcharType = leftType).getTypeId().isStringTypeId() && rightTypeId.isIntervalTypeId()||
                 (varcharType = rightType).getTypeId().isStringTypeId() && leftTypeId.isIntervalTypeId()
                    && operator.equals(PLUS_OP)) // when left is interval, only + is legal
                return new DataTypeDescriptor(varcharType.getPrecision() > 10 ? TypeId.DATETIME_ID : TypeId.DATE_ID, nullable);
        }
        else if (operator.equals(TIMES_OP) || operator.equals(DIVIDE_OP) || operator.equals(DIV_OP))
        {  
            // numeric / varchar and interval
            TypeId intervalId = null;
            if ((intervalId = leftTypeId).isIntervalTypeId() &&
                    (rightTypeId.isNumericTypeId() || rightTypeId.isStringTypeId())||
                (intervalId = rightTypeId).isIntervalTypeId() &&
                    (leftTypeId.isNumericTypeId() || leftTypeId.isStringTypeId()) &&
                    operator.equals(TIMES_OP)) // when right is interval, only * is legal
View Full Code Here

        {if (true) return typeDescriptor;}
    throw new Error("Missing return statement in function");
  }

  final public DataTypeDescriptor intervalQualifier() throws ParseException, StandardException {
    TypeId typeId, otherId = null;
    int[] precAndScale = new int[2];
    if ((getToken(2).kind == TO) ||
                           ((getToken(2).kind == LEFT_PAREN) &&
                            (getToken(5).kind == TO))) {
      typeId = intervalStartField(precAndScale);
View Full Code Here

                                      true, DataTypeDescriptor.intervalMaxWidth(typeId, precAndScale[0], precAndScale[1]));}
    throw new Error("Missing return statement in function");
  }

  final public TypeId intervalStartField(int[] precAndScale) throws ParseException, StandardException {
    TypeId typeId;
    Token prec;
    typeId = intervalNonSecond();
    switch (jj_nt.kind) {
    case LEFT_PAREN:
      jj_consume_token(LEFT_PAREN);
View Full Code Here

TOP

Related Classes of com.akiban.sql.types.TypeId

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.