Package com.google.visualization.datasource.base

Examples of com.google.visualization.datasource.base.InvalidQueryException


    public void setRowSkipping(int rowSkipping) throws InvalidQueryException {
        if(rowSkipping < 0) {
            String messageToLogAndUser = MessagesEnum.INVALID_SKIPPING.getMessageWithArgs(
                    localeForUserMessages, Integer.toString(rowSkipping));
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
        this.rowSkipping = rowSkipping;
    }
View Full Code Here


     */
    public void setRowLimit(int rowLimit) throws InvalidQueryException {
        if(rowLimit < -1) {
            String messageToLogAndUser = "Invalid value for row limit: " + rowLimit;
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
        this.rowLimit = rowLimit;
    }
View Full Code Here

    public void setRowOffset(int rowOffset) throws InvalidQueryException {
        if(rowOffset < 0) {
            String messageToLogAndUser = MessagesEnum.INVALID_OFFSET.getMessageWithArgs(
                    localeForUserMessages, Integer.toString(rowOffset));
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
        this.rowOffset = rowOffset;
    }
View Full Code Here

            for(AbstractColumn column : group.getColumns()) {
                if(!column.getAllAggregationColumns().isEmpty()) {
                    String messageToLogAndUser = MessagesEnum.CANNOT_BE_IN_GROUP_BY.getMessageWithArgs(
                            localeForUserMessages, column.toQueryString());
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }
        if(hasPivot()) {
            for(AbstractColumn column : pivot.getColumns()) {
                if(!column.getAllAggregationColumns().isEmpty()) {
                    String messageToLogAndUser = MessagesEnum.CANNOT_BE_IN_PIVOT.getMessageWithArgs(
                            localeForUserMessages, column.toQueryString());
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }
        if(hasFilter()) {
            List<AggregationColumn> filterAggregations = filter.getAggregationColumns();
            if(!filterAggregations.isEmpty()) {
                String messageToLogAndUser = MessagesEnum.CANNOT_BE_IN_WHERE.getMessageWithArgs(
                        localeForUserMessages, filterAggregations.get(0).toQueryString());
                ;
                log.error(messageToLogAndUser);
                throw new InvalidQueryException(messageToLogAndUser);
            }
        }

        // A column cannot appear both as an aggregation column and as a regular
        // column in the selection.
        for(SimpleColumn column1 : selectionSimple) {
            String id = column1.getColumnId();
            for(AggregationColumn column2 : selectionAggregated) {
                if(id.equals(column2.getAggregatedColumn().getId())) {
                    String messageToLogAndUser = MessagesEnum.SELECT_WITH_AND_WITHOUT_AGG.getMessageWithArgs(
                            localeForUserMessages, id);
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }

        // When aggregation is used, check that all selected columns are valid
        // (a column is valid if it is either grouped-by, or is a
        // scalar function column whose arguments are all valid columns).
        if(!selectionAggregated.isEmpty()) {
            for(AbstractColumn col : selectionColumns) {
                checkSelectedColumnWithGrouping(groupColumns, col);
            }
        }

        // Cannot group by a column that appears in an aggregation.
        if(hasSelection() && hasGroup()) {
            for(AggregationColumn column : selectionAggregated) {
                String id = column.getAggregatedColumn().getId();
                if(groupColumnIds.contains(id)) {
                    String messageToLogAndUser = MessagesEnum.COL_AGG_NOT_IN_SELECT.getMessageWithArgs(
                            localeForUserMessages, id);
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }

        // Cannot use grouping or pivoting when no aggregations are defined in the
        // selection.
        if(hasGroup() && selectionAggregated.isEmpty()) {
            String messageToLogAndUser = MessagesEnum.CANNOT_GROUP_WITNOUT_AGG.getMessage(
                    localeForUserMessages);
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
        if(hasPivot() && selectionAggregated.isEmpty()) {
            String messageToLogAndUser = MessagesEnum.CANNOT_PIVOT_WITNOUT_AGG.getMessage(
                    localeForUserMessages);
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }

        // Cannot order by a column that is not in the selection when aggregations
        // are defined.
        if(hasSort() && !selectionAggregated.isEmpty()) {
            for(AbstractColumn column : sort.getColumns()) {
                String messageToLogAndUser = MessagesEnum.COL_IN_ORDER_MUST_BE_IN_SELECT.getMessageWithArgs(
                        localeForUserMessages, column.toQueryString());
                checkColumnInList(selection.getColumns(), column,
                        messageToLogAndUser);
            }
        }

        // Cannot pivot by a column that appears in an aggregation.
        if(hasPivot()) {
            for(AggregationColumn column : selectionAggregated) {
                String id = column.getAggregatedColumn().getId();
                if(pivotColumnIds.contains(id)) {
                    String messageToLogAndUser = MessagesEnum.AGG_IN_SELECT_NO_PIVOT.getMessageWithArgs(
                            localeForUserMessages, id);
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }

        // Cannot have a column appear in both group by and pivot.
        if(hasGroup() && hasPivot()) {
            for(String id : groupColumnIds) {
                if(pivotColumnIds.contains(id)) {
                    String messageToLogAndUser = MessagesEnum.NO_COL_IN_GROUP_AND_PIVOT.getMessageWithArgs(
                            localeForUserMessages, id);
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }

        // Cannot order by aggregation column when pivoting is used.
        if(hasPivot() && !sortAggregated.isEmpty()) {
            AggregationColumn column = sortAggregated.get(0);
            String messageToLogAndUser = MessagesEnum.NO_AGG_IN_ORDER_WHEN_PIVOT.getMessageWithArgs(
                    localeForUserMessages, column.getAggregatedColumn().getId());
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }

        // Cannot order by aggregation columns that weren't defined in the
        // selection.
        for(AggregationColumn column : sortAggregated) {
            String messageToLogAndUser = MessagesEnum.AGG_IN_ORDER_NOT_IN_SELECT.getMessageWithArgs(
                    localeForUserMessages, column.toQueryString());
            checkColumnInList(selectionAggregated, column, messageToLogAndUser);
        }

        Set<AbstractColumn> labelColumns = (hasLabels()
                ? labels.getColumns() : Sets.<AbstractColumn>newHashSet());
        Set<AbstractColumn> formatColumns = (hasUserFormatOptions()
                ? userFormatOptions.getColumns() : Sets.<AbstractColumn>newHashSet());

        if(hasSelection()) {
            for(AbstractColumn col : labelColumns) {
                if(!selectionColumns.contains(col)) {
                    String messageToLogAndUser = MessagesEnum.LABEL_COL_NOT_IN_SELECT.getMessageWithArgs(
                            localeForUserMessages, col.toQueryString());
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
            for(AbstractColumn col : formatColumns) {
                if(!selectionColumns.contains(col)) {
                    String messageToLogAndUser = MessagesEnum.FORMAT_COL_NOT_IN_SELECT.getMessageWithArgs(
                            localeForUserMessages, col.toQueryString());
                    log.error(messageToLogAndUser);
                    throw new InvalidQueryException(messageToLogAndUser);
                }
            }
        }
    }
View Full Code Here

                checkColumnInList(columns, innerColumn, messageToLogAndUser);
            }
        }
        else {
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
    }
View Full Code Here

        if(col instanceof SimpleColumn) {
            if(!groupColumns.contains(col)) {
                String messageToLogAndUser = MessagesEnum.ADD_COL_TO_GROUP_BY_OR_AGG.getMessageWithArgs(
                        localeForUserMessages, col.getId());
                log.error(messageToLogAndUser);
                throw new InvalidQueryException(messageToLogAndUser);
            }
        }
        else if(col instanceof ScalarFunctionColumn) {
            // A selected scalar function column is valid if it is grouped by, or if
            // its inner columns are all valid.
View Full Code Here

     * @param types A list with parameters types.
     * @throws InvalidQueryException Thrown if the parameters are invalid.
     */
    public void validateParameters(List<ValueType> types) throws InvalidQueryException {
        if(types.size() != 2) {
            throw new InvalidQueryException("The function " + FUNCTION_NAME
                    + " requires 2 parmaeters ");
        }
        for(ValueType type : types) {
            if(type != ValueType.NUMBER) {
                throw new InvalidQueryException("Can't perform the function "
                        + FUNCTION_NAME + " on values that are not numbers");
            }
        }
    }
View Full Code Here

    public void addPattern(AbstractColumn column, String pattern) throws InvalidQueryException {
        if(columnPatterns.keySet().contains(column)) {
            String messageToLogAndUser = "Column [" + column.toString() + "] is "
                    + "specified more than once in FORMAT.";
            log.error(messageToLogAndUser);
            throw new InvalidQueryException(messageToLogAndUser);
        }
        columnPatterns.put(column, pattern);
    }
View Full Code Here

     * @param types A list of parameter types.
     * @throws InvalidQueryException Thrown if the parameters are invalid.
     */
    public void validateParameters(List<ValueType> types) throws InvalidQueryException {
        if(types.size() != 1) {
            throw new InvalidQueryException("Number of parameters for "
                    + timeComponent.getName() + "function is wrong: " + types.size());
        }
        switch(timeComponent) {
            case YEAR:
            case MONTH:
            case DAY:
            case QUARTER:
            case DAY_OF_WEEK:
                if((types.get(0) != ValueType.DATE)
                        && (types.get(0) != ValueType.DATETIME)) {
                    throw new InvalidQueryException("Can't perform the function "
                            + timeComponent.getName() + " on a column that is not a Date or"
                            + " a DateTime column");
                }
                break;
            case HOUR:
            case MINUTE:
            case SECOND:
            case MILLISECOND:
                if((types.get(0) != ValueType.TIMEOFDAY)
                        && (types.get(0) != ValueType.DATETIME)) {
                    throw new InvalidQueryException("Can't perform the function "
                            + timeComponent.getName() + " on a column that is not a "
                            + "TimeOfDay or a DateTime column");
                }
                break;
        }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void validateParameters(List<ValueType> types) throws InvalidQueryException {
        if(types.size() != 1) {
            throw new InvalidQueryException(FUNCTION_NAME +
                    " requires 1 parmaeter");
        }
        if(types.get(0) != ValueType.TEXT) {
            throw new InvalidQueryException(FUNCTION_NAME +
                    " takes a text parameter");
        }
    }
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.base.InvalidQueryException

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.