Package com.google.visualization.datasource.base

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


    for (String columnId : mentionedColumnIds) {
      if (!dataTable.containsColumn(columnId)) {
        String messageToLogAndUser = MessagesEnum.NO_COLUMN.getMessageWithArgs(
            dataTable.getLocaleForUserMessages(), columnId);
        log.error(messageToLogAndUser);
        throw new InvalidQueryException(messageToLogAndUser);
      }
    }

    // Check that all aggregation columns are valid (i.e., the aggregation type
    // matches the columns type).
    Set<AggregationColumn> mentionedAggregations = query.getAllAggregations();
    for (AggregationColumn agg : mentionedAggregations) {
      try {
        agg.validateColumn(dataTable);
      } catch (RuntimeException e) {
        log.error("A runtime exception has occured", e);
        throw new InvalidQueryException(e.getMessage());
      }
    }

    // Check that all scalar function columns are valid. (i.e., the scalar
    // function matches the columns types).
View Full Code Here


    ULocale userLocale = dataTable.getLocaleForUserMessages();
    switch (aggregationType) {
      case COUNT: case MAX: case MIN: break;
      case AVG: case SUM:
      if (valueType != ValueType.NUMBER) {
        throw new InvalidQueryException(MessagesEnum.AVG_SUM_ONLY_NUMERIC.getMessage(userLocale));
      }
      break;
      default: throw new RuntimeException(MessagesEnum.INVALID_AGG_TYPE.getMessageWithArgs(
          userLocale, aggregationType.toString()));
    }
View Full Code Here

        if (col.equals(selectionColumns.get(j))) {
          String[] args = {col.toString(), clauseName};
          String messageToLogAndUser = MessagesEnum.COLUMN_ONLY_ONCE.getMessageWithArgs(userLocale,
              args);
          log.error(messageToLogAndUser);
          throw new InvalidQueryException(messageToLogAndUser);
        }
      }
    }
  }
View Full Code Here

  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

      for (AbstractColumn innerColumn : innerColumns) {
        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.
      if (!groupColumns.contains(col)) {
View Full Code Here

      try {
        query = QueryParser.parseString(tqValue);
      } catch (ParseException ex) {
        String messageToUserAndLog = ex.getMessage();
        log.error("Parsing error: " + messageToUserAndLog);
        throw new InvalidQueryException(MessagesEnum.PARSE_ERROR.getMessageWithArgs(ulocale,
            messageToUserAndLog));
      }
      query.setLocaleForUserMessages(ulocale);
      query.validate();
    }
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.