Package com.akiban.sql.types

Examples of com.akiban.sql.types.DataTypeDescriptor


        return ret;
    }

    protected DataTypeDescriptor subqueryNode(SubqueryNode node) throws StandardException {
        if (node.getSubqueryType() == SubqueryNode.SubqueryType.EXPRESSION) {
            DataTypeDescriptor col1Type = node.getResultSet().getResultColumns().get(0).getType();
            if (col1Type == null)
                return null;
            else
                return col1Type.getNullabilityType(true);
        }
        else
            return new DataTypeDescriptor(TypeId.BOOLEAN_ID, true);
    }
View Full Code Here


    protected DataTypeDescriptor aggregateNode(AggregateNode node)
            throws StandardException {
        if (node.getAggregateName().equals("COUNT") ||
            node.getAggregateName().equals("COUNT(*)"))
            return new DataTypeDescriptor(TypeId.BIGINT_ID, false);

        ValueNode operand = node.getOperand();
        if ((operand == null) ||
            (operand.getType() == null))
            return null;
        if (node.getAggregateName().equals("AVG") &&
            operand.getType().getTypeId().isIntegerTypeId())
            return new DataTypeDescriptor(TypeId.DOUBLE_ID, true);
        return operand.getType().getNullabilityType(true);
    }
View Full Code Here

    protected DataTypeDescriptor concatenationOperatorNode(ConcatenationOperatorNode node)
            throws StandardException {
        ValueNode leftOperand = node.getLeftOperand();
        ValueNode rightOperand = node.getRightOperand();
        DataTypeDescriptor leftType = leftOperand.getType();
        DataTypeDescriptor rightType = rightOperand.getType();
        if ((leftType != null) &&
            !leftType.getTypeId().isStringTypeId()) {
            leftType = new DataTypeDescriptor(TypeId.VARCHAR_ID,
                                              leftType.isNullable(),
                                              leftType.getMaximumWidth());
            leftOperand = (ValueNode)node.getNodeFactory()
                .getNode(NodeTypes.CAST_NODE,
                         leftOperand, leftType,
                         node.getParserContext());
            node.setLeftOperand(leftOperand);
        }
        else if (isParameterOrUntypedNull(leftOperand)) {
            leftType = new DataTypeDescriptor(TypeId.VARCHAR_ID, true);
            leftOperand.setType(leftType);
        }
        if ((rightType != null) &&
            !rightType.getTypeId().isStringTypeId()) {
            rightType = new DataTypeDescriptor(TypeId.VARCHAR_ID,
                                              rightType.isNullable(),
                                              rightType.getMaximumWidth());
            rightOperand = (ValueNode)node.getNodeFactory()
                .getNode(NodeTypes.CAST_NODE,
                         rightOperand, rightType,
                         node.getParserContext());
            node.setRightOperand(rightOperand);
        }
        else if (isParameterOrUntypedNull(rightOperand)) {
            rightType = new DataTypeDescriptor(TypeId.VARCHAR_ID, true);
            rightOperand.setType(rightType);
        }
        if ((leftType == null) || (rightType == null))
            return null;
        return new DataTypeDescriptor(TypeId.VARCHAR_ID,
                                      leftType.isNullable() || rightType.isNullable(),
                                      leftType.getMaximumWidth() + rightType.getMaximumWidth(),
                                      CharacterTypeAttributes.mergeCollations(leftType.getCharacterAttributes(), rightType.getCharacterAttributes()));
    }
View Full Code Here

    }

    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

    throw new Error("Missing return statement in function");
  }

  final public StatementNode sequenceDefinition() throws ParseException, StandardException {
    TableName qualifiedSequenceName = null;
    DataTypeDescriptor dtd = null;
    Long initialValue = null;
    Long stepValue = null;
    Long maxValue = null;
    Long minValue = null;
    Boolean cycle = Boolean.FALSE;
View Full Code Here

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

  final public void procedureParameterDefinition(List[] list) throws ParseException, StandardException {
    DataTypeDescriptor typeDescriptor;
    String parameterName = null;
    Integer inout;
    inout = inoutParameter();
    if (dataTypeCheck(2)) {
      parameterName = identifier();
View Full Code Here

    9 - Boolean - definers rights
   10 - String - inline definition
*/
  final public StatementNode functionDefinition(Boolean createOrReplace) throws ParseException, StandardException {
    TableName functionName;
    DataTypeDescriptor returnType;
    Object[] functionElements = new Object[CreateAliasNode.ROUTINE_ELEMENT_COUNT];
    jj_consume_token(FUNCTION);
    functionName = qualifiedName();
    functionElements[0] = functionParameterList();
    jj_consume_token(RETURNS);
    returnType = functionReturnDataType();
    label_43:
    while (true) {
      routineElement(false, returnType.isRowMultiSet(), functionElements);
      switch (jj_nt.kind) {
      case AS:
      case EXTERNAL:
      case NO:
      case NOT:
View Full Code Here

TOP

Related Classes of com.akiban.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.