Package com.google.visualization.datasource.query

Examples of com.google.visualization.datasource.query.SimpleColumn


   * Test sorting by a number column.
   */
  public void testSortByNumberAscending() throws Exception {
    Query q = new Query();
    QuerySort sort = new QuerySort();
    sort.addSort(new ColumnSort(new SimpleColumn("weight"),
        SortOrder.ASCENDING));
    q.setSort(sort);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);

    assertEquals(3, res.getRows().size());
View Full Code Here


   * Test sorting by a number column.
   */
  public void testSortByNumberDescending() throws Exception {
    Query q = new Query();
    QuerySort sort = new QuerySort();
    sort.addSort(new ColumnSort(new SimpleColumn("weight"),
        SortOrder.DESCENDING));
    q.setSort(sort);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);

    assertEquals(3, res.getRows().size());
View Full Code Here

   * Test sorting by a text column.
   */
  public void testSortByTextAscending() throws Exception {
    Query q = new Query();
    QuerySort sort = new QuerySort();
    sort.addSort(new ColumnSort(new SimpleColumn("name"), SortOrder.ASCENDING));
    q.setSort(sort);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);

    assertEquals(3, res.getRows().size());
    assertEquals("aaa", res.getRows().get(0).getCells().get(0).toString());
View Full Code Here

   * Test sorting by a text column.
   */
  public void testSortByTextDescnding() throws Exception {
    Query q = new Query();
    QuerySort sort = new QuerySort();
    sort.addSort(new ColumnSort(new SimpleColumn("name"),
        SortOrder.DESCENDING));
    q.setSort(sort);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);

    assertEquals(3, res.getRows().size());
View Full Code Here

   * Test selection of the first col only.
   */
  public void testSelectionOfFirstCol() throws Exception {
    Query q = new Query();
    QuerySelection sel = new QuerySelection();
    sel.addColumn(new SimpleColumn("name"));
    q.setSelection(sel);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);
    List<ColumnDescription> cols = res.getColumnDescriptions();

    assertEquals(1, cols.size());
View Full Code Here

   * Test selection of all but the first col.
   */
  public void testSelectionOfAllButFirstCol() throws Exception {
    Query q = new Query();
    QuerySelection sel = new QuerySelection();
    sel.addColumn(new SimpleColumn("weight"));
    sel.addColumn(new SimpleColumn("isPig"));
    q.setSelection(sel);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);
    List<ColumnDescription> cols = res.getColumnDescriptions();

    assertEquals(2, cols.size());
View Full Code Here

   * Test sorting by a text column, while this is the only selected column.
   */
  public void testSelectionAndSortByTextDescending() throws Exception {
    Query q = new Query();
    QuerySort sort = new QuerySort();
    sort.addSort(new ColumnSort(new SimpleColumn("name"),
        SortOrder.DESCENDING));
    q.setSort(sort);

    QuerySelection selection = new QuerySelection();
    selection.addColumn(new SimpleColumn("name"));
    q.setSelection(selection);
    DataTable res = QueryEngine.executeQuery(q, input, ULocale.US);
    List<ColumnDescription> cols = res.getColumnDescriptions();

    assertEquals(1, cols.size());
View Full Code Here

    // select max(songs), min(songs), year, avg(songs), sum(sales)
    // group by year, band
    Query q = new Query();
    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("Year"));
    group.addColumn(new SimpleColumn("Band"));
    q.setGroup(group);
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.MAX));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.MIN));
    selection.addColumn(new SimpleColumn("Year"));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Songs"),
        AggregationType.AVG));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.SUM));
    q.setSelection(selection);
    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);
View Full Code Here

    // select max(sales), year, min(sales), avg(fans)
    // group by year
    // pivot by band, songs
    Query q = new Query();
    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("Year"));
    q.setGroup(group);
    QueryPivot pivot = new QueryPivot();
    pivot.addColumn(new SimpleColumn("Band"));
    pivot.addColumn(new SimpleColumn("Songs"));
    q.setPivot(pivot);
    QuerySelection selection = new QuerySelection();
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.MAX));
    selection.addColumn(new SimpleColumn("Year"));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Sales"),
        AggregationType.MIN));
    selection.addColumn(new AggregationColumn(new SimpleColumn("Fans"),
        AggregationType.AVG));
    q.setSelection(selection);
    q.validate();

    DataTable result = QueryEngine.executeQuery(q, res, ULocale.US);
View Full Code Here

          // The id here is the id generated by the data source for the column containing
          // the aggregated data, e.g., max-B.
          String id = column.getId();
          // MIN is chosen arbitrarily, because there will be exactly one.
          completionSelection.addColumn(
              new AggregationColumn(new SimpleColumn(id), AggregationType.MIN));
        }
      }

      completionQuery.setSelection(completionSelection);
    } else {
      // When there is no pivoting, sql does everything (except skipping, options, labels, format).
      dataSourceQuery.copyFrom(query);
      dataSourceQuery.setOptions(null);
      completionQuery.setOptions(query.getOptions());
      try {
        // If there is skipping pagination should be done in the completion query
        if (query.hasRowSkipping()) {
          dataSourceQuery.setRowSkipping(0);
          dataSourceQuery.setRowLimit(-1);
          dataSourceQuery.setRowOffset(0);
         
          completionQuery.copyRowSkipping(query);
          completionQuery.copyRowLimit(query);
          completionQuery.copyRowOffset(query);
        }
        if (query.hasLabels()) {
          dataSourceQuery.setLabels(null);
          QueryLabels labels = query.getLabels();
          QueryLabels newLabels = new QueryLabels();
          for (AbstractColumn column : labels.getColumns()) {
            newLabels.addLabel(new SimpleColumn(column.getId()), labels.getLabel(column));
          }
          completionQuery.setLabels(newLabels);
        }
        if (query.hasUserFormatOptions()) {
          dataSourceQuery.setUserFormatOptions(null);
          QueryFormat formats = query.getUserFormatOptions();
          QueryFormat newFormats = new QueryFormat();
          for (AbstractColumn column : formats.getColumns()) {
            newFormats.addPattern(new SimpleColumn(column.getId()), formats.getPattern(column));
          }
          completionQuery.setUserFormatOptions(newFormats);
        }
      } catch (InvalidQueryException e) {
        // Should not happen.
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.query.SimpleColumn

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.