Package com.foundationdb.sql.types

Examples of com.foundationdb.sql.types.DataTypeDescriptor


        }

        protected int limitParameter(ParameterNode param) throws StandardException {
            assert (parameters != null) && parameters.contains(param) : param;
            TInstance type;
            DataTypeDescriptor sqlType = param.getType();
            if (sqlType == null) {
                type = typesTranslator.typeClassForJDBCType(Types.INTEGER).instance(true);
                sqlType = type.dataTypeDescriptor();
                param.setType(sqlType);
            }
View Full Code Here


                                              List<ExpressionNode> projects)
                throws StandardException {
            if (valueNode == null) {
                return ConstantExpression.typedNull(null, null, null);
            }
            DataTypeDescriptor sqlType = valueNode.getType();
            TInstance type = typesTranslator.typeForSQLType(sqlType);
            if (valueNode instanceof ColumnReference) {
                ColumnBinding cb = (ColumnBinding)((ColumnReference)valueNode).getUserData();
                if (cb == null)
                    throw new UnsupportedSQLException("Unsupported column", valueNode);
                Joinable joinNode = joinNodes.get(cb.getFromTable());
                if ((joinNode == null) &&
                    (cb.getFromTable() == null) &&
                    (projects != null) &&
                    (cb.getResultColumn() != null)) {
                    // Alias: use result column expression.
                    return projects.get(cb.getResultColumn().getColumnPosition()-1);
                }
                if (!(joinNode instanceof ColumnSource))
                    throw new UnsupportedSQLException("Unsupported column", valueNode);
                Column column = cb.getColumn();
                if (column != null)
                    return new ColumnExpression(((TableSource)joinNode), column,
                            sqlType, valueNode);
                else
                    return new ColumnExpression(((ColumnSource)joinNode),
                                                cb.getFromTable().getResultColumns().indexOf(cb.getResultColumn()),
                            sqlType, valueNode, type);
            }
            else if (valueNode instanceof ConstantNode) {
                if (valueNode instanceof BooleanConstantNode)
                    return new BooleanConstantExpression((Boolean)((ConstantNode)valueNode).getValue(),
                            sqlType, valueNode, type);
                else if (valueNode instanceof UntypedNullConstantNode) {
                    return ConstantExpression.typedNull(sqlType, valueNode, type);
                }
                else {
                    Object value = ((ConstantNode)valueNode).getValue();
                    if (value instanceof Integer) {
                        int ival = ((Integer)value).intValue();
                        if ((ival >= Byte.MIN_VALUE) && (ival <= Byte.MAX_VALUE))
                            value = new Byte((byte)ival);
                        else if ((ival >= Short.MIN_VALUE) && (ival <= Short.MAX_VALUE))
                            value = new Short((short)ival);
                        ExpressionNode constInt = new ConstantExpression(value, sqlType, valueNode, type);
                        return constInt;
                    }
                    if ((value instanceof String) &&
                        ((sqlType != null) &&
                         (sqlType.getTypeId() == TypeId.CHAR_ID))) {
                        // TODO: Make a char literal into a VARCHAR instead of a CHAR.
                        // It shouldn't matter, but some of the overloads aren't quite
                        // right.
                        type = typesTranslator.typeForString((String) value);
                    }
                    return new ConstantExpression(value, sqlType, valueNode, type);
                }
            }
            else if (valueNode instanceof ParameterNode) {
                assert (parameters != null) && parameters.contains(valueNode) : valueNode;
                return new ParameterExpression(((ParameterNode)valueNode)
                                               .getParameterNumber(),
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof CastNode)
                return new CastExpression(toExpression(((CastNode)valueNode)
                                                       .getCastOperand(),
                                                       projects),
                        sqlType, valueNode, type);
            else if (valueNode instanceof AggregateNode) {
                AggregateNode aggregateNode = (AggregateNode)valueNode;
                String function = aggregateNode.getAggregateName();
                ExpressionNode operand = null;
                if ("COUNT(*)".equals(function)) {
                    function = "COUNT";
                }
                else {
                    operand = toExpression(aggregateNode.getOperand(), projects);
                    if (hasAggregateFunction(operand)) {
                        throw new UnsupportedSQLException("Cannot nest aggregate functions",
                                                          aggregateNode);
                    }
                }
               
                if (aggregateNode instanceof GroupConcatNode)
                {
                    GroupConcatNode groupConcat = (GroupConcatNode) aggregateNode;
                    List<OrderByExpression> sorts = null;
                    OrderByList orderByList = groupConcat.getOrderBy();
                   
                    if (orderByList != null)
                    {
                        sorts = new ArrayList<>();
                        for (OrderByColumn orderByColumn : orderByList)
                        {
                            ExpressionNode expression = toOrderGroupBy(orderByColumn.getExpression(), projects, "ORDER");
                            sorts.add(new OrderByExpression(expression,
                                                            orderByColumn.isAscending()));
                        }
                    }
                   
                    return new AggregateFunctionExpression(function,
                                                       operand,
                                                       aggregateNode.isDistinct(),
                            sqlType, valueNode, type,
                                                       groupConcat.getSeparator(),
                                                       sorts);
                }
                else
                    return new AggregateFunctionExpression(function,
                                                           operand,
                                                           aggregateNode.isDistinct(),
                            sqlType, valueNode, type,
                                                           null,
                                                           null);
            }
            else if (isConditionExpression(valueNode)) {
                return toCondition(valueNode, projects);
            }
            else if (valueNode instanceof UnaryOperatorNode) {
                if (valueNode instanceof WindowFunctionNode) {
                    throw new UnsupportedSQLException("Window", valueNode);
                }
                UnaryOperatorNode unary = (UnaryOperatorNode)valueNode;
                List<ExpressionNode> operands = new ArrayList<>(1);
                operands.add(toExpression(unary.getOperand(), projects));
                return new FunctionExpression(unary.getMethodName(),
                                              operands,
                        sqlType, unary, type);
            }
            else if (valueNode instanceof BinaryOperatorNode) {
                BinaryOperatorNode binary = (BinaryOperatorNode)valueNode;
                List<ExpressionNode> operands = new ArrayList<>(2);
                int nodeType = valueNode.getNodeType();
                switch (nodeType) {
                case NodeTypes.CONCATENATION_OPERATOR_NODE:
                    // Operator is binary but function is nary: collapse.
                    while (true) {
                        operands.add(toExpression(binary.getLeftOperand(), projects));
                        ValueNode right = binary.getRightOperand();
                        if (right.getNodeType() != nodeType) {
                            operands.add(toExpression(right, projects));
                            break;
                        }
                        binary = (BinaryOperatorNode)right;
                    }
                    break;
                default:
                    operands.add(toExpression(binary.getLeftOperand(), projects));
                    operands.add(toExpression(binary.getRightOperand(), projects));
                }
                return new FunctionExpression(binary.getMethodName(),
                                              operands,
                        sqlType, binary, type);
            }
            else if (valueNode instanceof TernaryOperatorNode) {
                TernaryOperatorNode ternary = (TernaryOperatorNode)valueNode;
                List<ExpressionNode> operands = new ArrayList<>(3);
                operands.add(toExpression(ternary.getReceiver(), projects));
                operands.add(toExpression(ternary.getLeftOperand(), projects));
               
                // java null means not present
                ValueNode third = ternary.getRightOperand();
                if (third != null)
                    operands.add(toExpression(third, projects));

                return new FunctionExpression(ternary.getMethodName(),
                                              operands,
                        sqlType, ternary, type);
            }
            else if (valueNode instanceof CoalesceFunctionNode) {
                CoalesceFunctionNode coalesce = (CoalesceFunctionNode)valueNode;
                List<ExpressionNode> operands = new ArrayList<>();
                for (ValueNode value : coalesce.getArgumentsList()) {
                    operands.add(toExpression(value, projects));
                }
                return new FunctionExpression(coalesce.getFunctionName(),
                                              operands,
                        sqlType, coalesce, type);
            }
            else if (valueNode instanceof SubqueryNode) {
                SubqueryNode subqueryNode = (SubqueryNode)valueNode;
                pushEquivalenceFinder();
                PlanNode subquerySelect = toQueryForSelect(subqueryNode.getResultSet(),
                                                           subqueryNode.getOrderByList(),
                                                           subqueryNode.getOffset(),
                                                           subqueryNode.getFetchFirst(),
                                                           false);
                Subquery subquery = new Subquery(subquerySelect, peekEquivalenceFinder());
                popEquivalenceFinder();
                if ((sqlType != null) && sqlType.getTypeId().isRowMultiSet())
                    return new SubqueryResultSetExpression(subquery, sqlType,
                                                           subqueryNode, type);
                else
                    return new SubqueryValueExpression(subquery, sqlType,
                                                       subqueryNode, type);
View Full Code Here

                if (methodCall.getMethodParameters() != null) {
                    for (JavaValueNode javaValue : methodCall.getMethodParameters()) {
                        operands.add(toExpression(javaValue, null, false, projects));
                    }
                }
                DataTypeDescriptor sqlType = valueNode.getType();
                TInstance type = typesTranslator.typeForSQLType(sqlType);
                Routine routine = (Routine)methodCall.getUserData();
                if (routine != null) {
                    if (asCondition)
                        return new RoutineCondition(routine, operands,
View Full Code Here

    public static List<PostgresType> columnTypes(LoadablePlan<?> plan,
                                                 TypesTranslator typesTranslator)
    {
        List<PostgresType> columnTypes = new ArrayList<>();
        for (int jdbcType : plan.jdbcTypes()) {
            DataTypeDescriptor sqlType = DataTypeDescriptor.getBuiltInDataTypeDescriptor(jdbcType);
            TInstance type = typesTranslator.typeForSQLType(sqlType);
            columnTypes.add(PostgresType.fromDerby(sqlType, type));
        }
        return columnTypes;
    }
View Full Code Here

        int[] jdbcTypes = plan.jdbcTypes();
        List<ResultColumn> columns = new ArrayList<>(jdbcTypes.length);
        for (int i = 0; i < jdbcTypes.length; i++) {
            String name = columnNames.get(i);
            int jdbcType = jdbcTypes[i];
            DataTypeDescriptor sqlType = DataTypeDescriptor.getBuiltInDataTypeDescriptor(jdbcType);
            TInstance type = context.getTypesTranslator().typeForSQLType(sqlType);
            ResultColumn column = new ResultColumn(name, jdbcType, sqlType,
                                                   null, type, null);
            columns.add(column);
        }
View Full Code Here

            int usage = invocation.parameterUsage(i);
            if (usage < 0) continue;
            Parameter parameter = invocation.getRoutineParameter(usage);
            TInstance type = parameter.getType();
            int jdbcType = type.typeClass().jdbcType();
            DataTypeDescriptor sqlType = type.dataTypeDescriptor();
            ptypes[i] = new ParameterType(parameter, sqlType, jdbcType, type);
        }
        return new JDBCParameterMetaData(context.getTypesTranslator(), Arrays.asList(ptypes));
    }
View Full Code Here

            TypesTranslator typesTranslator = rulesContext.getTypesTranslator();
            BasePlannable.ParameterType[] result = new BasePlannable.ParameterType[nparams];
            for (ParameterNode param : params) {
                int paramNo = param.getParameterNumber();
                if (result[paramNo] == null) {
                    DataTypeDescriptor sqlType = param.getType();
                    TInstance type = (TInstance)param.getUserData();
                    if (type == null)
                        assert param.isReturnOutputParam() : param;
                    else
                        result[paramNo] = new BasePlannable.ParameterType(sqlType, type);
View Full Code Here

                    type = StringAttribute.copyWithCollation(type, n.getSQLtype().getCharacterAttributes());
                    tpv = new TPreptimeValue(type, tpv.value());
                    n.setPreptimeValue(tpv);
                }
                if (type != null) {
                    DataTypeDescriptor newDtd = type.dataTypeDescriptor();
                    n.setSQLtype(newDtd);
                }
            }
            return n;
        }
View Full Code Here

            }
            node.setTInstances(instances);
        }

        ExpressionNode handleCastExpression(CastExpression expression) {
            DataTypeDescriptor dtd = expression.getSQLtype();
            TInstance type = typesTranslator.typeForSQLType(dtd);
            expression.setPreptimeValue(new TPreptimeValue(type));
            if (expression.getOperand() instanceof ParameterExpression) {
                parametersSync.set(expression.getOperand(), type);
            }
View Full Code Here

            expression.setPreptimeValue(tpv);
            return expression;
        }

        ExpressionNode handleSubqueryResultSetExpression(SubqueryResultSetExpression expression) {
            DataTypeDescriptor sqlType = expression.getSQLtype();
            if (sqlType.isRowMultiSet()) {
                setMissingRowMultiSetColumnTypes(sqlType, expression.getSubquery());
            }
            TPreptimeValue tpv = new TPreptimeValue(typesTranslator.typeForSQLType(sqlType));
            expression.setPreptimeValue(tpv);
            return expression;
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.