Package com.foundationdb.sql.types

Examples of com.foundationdb.sql.types.DataTypeDescriptor


    }

    protected ValueNode collateNode(ExplicitCollateNode node)
            throws StandardException {
        ValueNode operand = node.getOperand();
        DataTypeDescriptor origType = operand.getType();
        if (origType != null) {
            if (!origType.getTypeId().isStringTypeId())
                throw new StandardException("Collation not allowed for " + origType);
            CharacterTypeAttributes characterAttributes =
                CharacterTypeAttributes.forCollation(origType.getCharacterAttributes(),
                                                     node.getCollation());
            operand.setType(new DataTypeDescriptor(origType, characterAttributes));
        }
        return operand;
    }
View Full Code Here


        return operand;
    }

    protected DataTypeDescriptor dominantType(ValueNodeList nodeList)
            throws StandardException {
        DataTypeDescriptor result = null;
        for (ValueNode node : nodeList) {
            if (node.getType() == null) continue;
            if (result == null)
                result = node.getType();
            else
                result = result.getDominantType(node.getType());
        }
        if (result != null) {
            for (int i = 0; i < nodeList.size(); i++) {
                ValueNode node = nodeList.get(i);
                if (isParameterOrUntypedNull(node))
                    node.setType(result.getNullabilityType(true));
                else if (addDominantCast(result, node.getType())) {
                    node = (ValueNode)node.getNodeFactory()
                        .getNode(NodeTypes.CAST_NODE,
                                 node,
                                 result.getNullabilityType(node.getType().isNullable()),
                                 node.getParserContext());
                    nodeList.set(i, node);
                }
            }
        }
View Full Code Here

    }

    private void checkBooleanClause(ValueNode clause, String which)
            throws StandardException {
        if (clause != null) {
            DataTypeDescriptor type = clause.getType();
            if (type == null) {
                assert false : "Type not set yet";
                return;
            }
            if (!type.getTypeId().isBooleanTypeId())
                throw new StandardException("Non-boolean " + which + " clause");
        }
    }
View Full Code Here

                // 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
                return new DataTypeDescriptor(intervalId, nullable);           
        }       

        // Unsupported
        return super.resolveArithmeticOperation(leftType, rightType, operator);
    }
View Full Code Here

        if (rightTypeId.isDateTimeTimeStampTypeId()) {
            if (operator.equals(TypeCompiler.MINUS_OP)) {
                switch (rightTypeId.getTypeFormatId()) {
                case TypeId.FormatIds.DATE_TYPE_ID:
                    // DATE - DATE is INTERVAL DAY
                    return new DataTypeDescriptor(TypeId.INTERVAL_DAY_ID, nullable);
                default:
                    // DATE - 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_YEAR_MONTH_ID:
                    // DATE +/- month year interval is DATE
                    return leftType.getNullabilityType(nullable);
                case TypeId.FormatIds.INTERVAL_DAY_SECOND_ID:
                    if (rightTypeId == TypeId.INTERVAL_DAY_ID)
                        // DATE +/- INTERVAL DAY is DATE
                        return leftType.getNullabilityType(nullable);
                }
                // DATE +/- other interval is TIMESTAMP
                return new DataTypeDescriptor(TypeId.TIMESTAMP_ID, nullable);
            }
        }

        // Unsupported
        return super.resolveArithmeticOperation(leftType, rightType, operator);
View Full Code Here

        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)) {
View Full Code Here

                OrNode newOr = (OrNode)nodeFactory.getNode(NodeTypes.OR_NODE,
                                                           leftBCO,
                                                           rightBCO,
                                                           parserContext);
                /* Work out types (only nullability). */
                DataTypeDescriptor leftType = leftOperand.getType();
                DataTypeDescriptor right0Type = rightOperandList.get(0).getType();
                DataTypeDescriptor right1Type = rightOperandList.get(1).getType();
                boolean orNullable = false;
                if ((leftType != null) && (right0Type != null)) {
                    boolean nullable = leftType.isNullable() || right0Type.isNullable();
                    DataTypeDescriptor leftBCType = new DataTypeDescriptor(TypeId.BOOLEAN_ID,
                                                                           nullable);
                    leftBCO.setType(leftBCType);
                    orNullable = nullable;
                }
                if ((leftType != null) && (right1Type != null)) {
                    boolean nullable = leftType.isNullable() || right1Type.isNullable();
                    DataTypeDescriptor rightBCType = new DataTypeDescriptor(TypeId.BOOLEAN_ID,
                                                                            nullable);
                    rightBCO.setType(rightBCType);
                    orNullable |= nullable;
                }
                if ((leftType != null) && (right0Type != null) && (right1Type != null))
                    newOr.setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, orNullable));
                return newOr;
            }
            break;
        case NodeTypes.IN_LIST_OPERATOR_NODE:
                /* We want to convert the IN List into = OR = ... as * described below. */
 
View Full Code Here

            (node.getType().getTypeId().isBooleanTypeId()))
            return node;
        return (ValueNode)
            nodeFactory.getNode(NodeTypes.CAST_NODE,
                                node,
                                new DataTypeDescriptor(TypeId.BOOLEAN_ID,
                                                       node.getType().isNullable()),
                                parserContext);
    }
View Full Code Here

            nodeFactory.getNode(NodeTypes.BINARY_EQUALS_OPERATOR_NODE,
                                node, trueNode,
                                parserContext);
        if (node.getType() != null) {
            boolean nullableResult = node.getType().isNullable();
            equalsNode.setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID,
                                                      nullableResult));
        }
        return equalsNode;
    }
View Full Code Here

                AndNode andNode = (AndNode)nodeFactory.getNode(NodeTypes.AND_NODE,
                                                               node, trueNode,
                                                               parserContext);
                if (node.getType() != null) {
                    boolean nullableResult = node.getType().isNullable();
                    andNode.setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID,
                                                           nullableResult));
                }
                return andNode;
            }
        }
View Full Code Here

TOP

Related Classes of com.foundationdb.sql.types.DataTypeDescriptor

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.