Package com.foundationdb.server.error

Examples of com.foundationdb.server.error.UnsupportedSQLException


                }
                else {
                    offset = getIntegerConstant(offsetClause,
                                                "OFFSET must be constant integer");
                    if (offset < 0)
                        throw new UnsupportedSQLException("OFFSET must not be negative",
                                                          offsetClause);
                }
            }
            if (limitClause != null) {
                if (limitClause instanceof ParameterNode) {
                    limit = limitParameter((ParameterNode)limitClause);
                    limitIsParameter = true;
                }
                else {
                    limit = getIntegerConstant(limitClause,
                                               "LIMIT must be constant integer");
                    if (limit < 0)
                        throw new UnsupportedSQLException("LIMIT must not be negative",
                                                          limitClause);
                }
            }
            return new Limit(input,
                             offset, offsetIsParameter,
View Full Code Here


            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);
            }
            else if (valueNode instanceof JavaToSQLValueNode) {
                return toExpression(((JavaToSQLValueNode)valueNode).getJavaValueNode(),
                                    valueNode,
                                    false,
                                    projects);
            }
            else if (valueNode instanceof CurrentDatetimeOperatorNode) {
                String functionName = FunctionsTypeComputer.currentDatetimeFunctionName((CurrentDatetimeOperatorNode)valueNode);
                if (functionName == null)
                    throw new UnsupportedSQLException("Unsupported datetime function", valueNode);
                return new FunctionExpression(functionName,
                                              Collections.<ExpressionNode>emptyList(),
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof SpecialFunctionNode) {
                String functionName = FunctionsTypeComputer.specialFunctionName((SpecialFunctionNode)valueNode);
                if (functionName == null)
                    throw new UnsupportedSQLException("Unsupported special function", valueNode);
                return new FunctionExpression(functionName,
                                              Collections.<ExpressionNode>emptyList(),
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof ConditionalNode) {
                ConditionalNode cond = (ConditionalNode)valueNode;
                return new IfElseExpression(toConditions(cond.getTestCondition(), projects),
                                            toExpression(cond.getThenNode(), projects),
                                            toExpression(cond.getElseNode(), projects),
                        sqlType, cond, type);
            }
            else if (valueNode instanceof SimpleCaseNode) {
                SimpleCaseNode caseNode = (SimpleCaseNode)valueNode;
                ExpressionNode operand = toExpression(caseNode.getOperand(), projects);
                int ncases = caseNode.getNumberOfCases();
                ExpressionNode expr;
                if (caseNode.getElseValue() != null)
                    expr = toExpression(caseNode.getElseValue(), projects);
                else
                    expr = ConstantExpression.typedNull(sqlType, valueNode, type);
                for (int i = ncases - 1; i >= 0; i--) {
                    ConditionList conds = new ConditionList(1);
                    conds.add(new ComparisonCondition(Comparison.EQ, operand, toExpression(caseNode.getCaseOperand(i), projects), sqlType, caseNode, type));
                    expr = new IfElseExpression(conds,
                                                toExpression(caseNode.getResultValue(i), projects),
                                                expr, sqlType, caseNode, type);
                }
                return expr;
            }
            else if (valueNode instanceof SimpleCaseNode) {
                SimpleCaseNode caseNode = (SimpleCaseNode)valueNode;
                ExpressionNode operand = toExpression(caseNode.getOperand(), projects);
                int ncases = caseNode.getNumberOfCases();
                ExpressionNode expr;
                if (caseNode.getElseValue() != null)
                    expr = toExpression(caseNode.getElseValue(), projects);
                else
                    expr = ConstantExpression.typedNull(sqlType, valueNode, type);
                for (int i = ncases - 1; i >= 0; i--) {
                    ConditionList conds = new ConditionList(1);
                    conds.add(new ComparisonCondition(Comparison.EQ, operand, toExpression(caseNode.getCaseOperand(i), projects), sqlType, caseNode, type));
                    expr = new IfElseExpression(conds,
                                                toExpression(caseNode.getResultValue(i), projects),
                                                expr, sqlType, caseNode, type);
                }
                return expr;
            }
            else if (valueNode instanceof NextSequenceNode) {
                NextSequenceNode seqNode = (NextSequenceNode)valueNode;
                List<ExpressionNode> params = new ArrayList<>(2);

                String schema = seqNode.getSequenceName().hasSchema() ?
                        seqNode.getSequenceName().getSchemaName() :
                            rulesContext.getDefaultSchemaName();
                // Extract the (potential) schema name as the first parameter
                TInstance schemaType = typesTranslator.typeForString(schema);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(schemaType, schema))));
                // Extract the schema name as the second parameter
                String sequence = seqNode.getSequenceName().getTableName();
                TInstance sequenceType = typesTranslator.typeForString(sequence);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(sequenceType, sequence))));
               
                return new FunctionExpression ("nextval", params,
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof CurrentSequenceNode) {
                CurrentSequenceNode seqNode = (CurrentSequenceNode)valueNode;
                List<ExpressionNode> params = new ArrayList<>(2);

                String schema = seqNode.getSequenceName().hasSchema() ?
                        seqNode.getSequenceName().getSchemaName() :
                            rulesContext.getDefaultSchemaName();
                // Extract the (potential) schema name as the first parameter
                TInstance schemaType = typesTranslator.typeForString(schema);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(schemaType, schema))));
                // Extract the schema name as the second parameter
                String sequence = seqNode.getSequenceName().getTableName();
                TInstance sequenceType = typesTranslator.typeForString(sequence);
                params.add(new ConstantExpression(
                        new TPreptimeValue(new Value(sequenceType, sequence))));
               
                return new FunctionExpression ("currval", params,
                        sqlType, valueNode, type);
            }
            else if (valueNode instanceof DefaultNode) {
                Column column = (Column)valueNode.getUserData();
                if (column == null)
                    throw new DefaultOutsideInsertException(valueNode);
                return new ColumnDefaultExpression(column, sqlType, valueNode, type);
            }
            else
                throw new UnsupportedSQLException("Unsupported operand", valueNode);
        }
View Full Code Here

            else if (javaToSQL instanceof SQLToJavaValueNode) {
                return toExpression(((SQLToJavaValueNode)javaToSQL).getSQLValueNode(),
                                    projects);
            }
            else
                throw new UnsupportedSQLException("Unsupported operand", valueNode);
        }
View Full Code Here

                        return column;
                }
            }
            if (errmsg == null)
                return null;
            throw new UnsupportedSQLException(errmsg, value);
        }
View Full Code Here

            if (value instanceof NumericConstantNode) {
                Object number = ((NumericConstantNode)value).getValue();
                if (number instanceof Integer)
                    return ((Integer)number).intValue();
            }
            throw new UnsupportedSQLException(errmsg, value);
        }
View Full Code Here

                        // Make the order predictable for tests.
                        ConditionExpression temp = c1;
                        c1 = c2;
                        c2 = temp;
                    }
                    throw new UnsupportedSQLException("Found two possible parent joins",
                                                      c2.getSQLsource());
                }
            }
        }
        if (parentTable == null) return null;
View Full Code Here

            encoding = copyStmt.getEncoding();
            if (encoding == null)
                encoding = server.getMessenger().getEncoding();
            break;
        default:
            throw new UnsupportedSQLException("COPY FORMAT " + format);
        }
        commitFrequency = copyStmt.getCommitFrequency();
        if (commitFrequency == 0) {
            commitFrequency = server.getTransactionPeriodicallyCommit() == ServerTransaction.PeriodicallyCommit.OFF ?
                    ExternalDataService.COMMIT_FREQUENCY_NEVER :
View Full Code Here

            break;
        case ANTI:
            map.setInner(new OnlyIfEmpty(map.getInner()));
            break;
        default:
            throw new UnsupportedSQLException("complex join type " + map, null);
        }
        map.setJoinType(null)// No longer special.
    }
View Full Code Here

                                }
                            }
                        break;
                    }
                    if((action != null) && checkForReferencing(stmt.getInput(), action, fk.getReferencingTable())) {
                        throw new UnsupportedSQLException(
                            String.format("DML includes both referenced and referencing table %s with FOREIGN KEY action %s",
                                          fk.getReferencingTable().getName().toString(),
                                          action.name()));
                    }
                }
            }

            if(bufferRequired) {
                switch(stmt.getType()) {
                    case INSERT:
                    case DELETE:
                        injectBufferNode(stmt);
                        break;
                    case UPDATE:
                        if(indexWasUnique) {
                            if(isFKReferenced) {
                                throw new UnsupportedSQLException("Halloween vulnerable query on referenced table");
                            }
                            DMLStatement newDML = transformUpdate(stmt, updateStmt);
                            plan.setPlan(newDML);
                        } else {
                            injectBufferNode(stmt);
View Full Code Here

        tables = new ArrayList<>();
        addTables(root, tables);
        int ntables = tables.size();
        if (ntables > 30)
            // TODO: Need to select some simpler algorithm that scales better.
            throw new UnsupportedSQLException("Too many tables in query: " + ntables,
                                              null);
        tableBitSets = new HashMap<>(ntables);
        for (int i = 0; i < ntables; i++) {
            Joinable table = tables.get(i);
            Long bitset = JoinableBitSet.of(i);
View Full Code Here

TOP

Related Classes of com.foundationdb.server.error.UnsupportedSQLException

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.