Package com.google.visualization.datasource.query

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


    // select day(hireDate) + age * hour(seniorityStartTime), age
    Query q = new Query();

    // Add selection.
    QuerySelection selection = new QuerySelection();
    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2 = new SimpleColumn("age");
    AbstractColumn col3  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col4 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col2, col3), Product.getInstance());
    AbstractColumn col5 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col4), Sum.getInstance());
    selection.addColumn(col5);
    selection.addColumn(new SimpleColumn("age"));
    q.setSelection(selection);
    q.validate();
View Full Code Here


    // select sum(age), day(hireDate) - hour(seniorityStartTime)
    // group by day(hireDate) - hour(seniorityStartTime)
    Query q = new Query();

    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col3 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col2),
        Difference.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

    // select day(hireDate), hour(seniorityStartTime) where
    // day(hireDate) - hour(seniorityStartTime) < -5
    // group by day(hireDate) - hour(seniorityStartTime)
    Query q = new Query();

    AbstractColumn col1  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("hireDate")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.DAY));
    AbstractColumn col2  = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(
            new SimpleColumn("seniorityStartTime")),
        TimeComponentExtractor.getInstance(
            TimeComponentExtractor.TimeComponent.HOUR));
    AbstractColumn col3 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(col1, col2),
        Difference.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

    DataTable res = MockDataSource.getData(0);

    // selection with modulo ('weight' is a column id): "select weight, weight % 10"
    Query q = new Query();

    AbstractColumn col1 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(), new Constant(new NumberValue(10)));
    AbstractColumn col2 = new ScalarFunctionColumn(
        Lists.<AbstractColumn>newArrayList(new SimpleColumn("weight"), col1),
        Modulo.getInstance());

    // Add selection
    QuerySelection selection = new QuerySelection();
View Full Code Here

    QuerySelection selection = new QuerySelection();
    selection.addColumn(new SimpleColumn("name"));
    selection.addColumn(new SimpleColumn("weight"));
    q.setSelection(selection);

    AbstractColumn col1 = new ScalarFunctionColumn(
      Lists.<AbstractColumn>newArrayList(), new Constant(new NumberValue(2)));
    AbstractColumn col2 = new ScalarFunctionColumn(
      Lists.<AbstractColumn>newArrayList(new SimpleColumn("weight"), col1),
      Modulo.getInstance());

    QueryFilter filter = new ColumnValueFilter(col2,
      new NumberValue(0), ComparisonFilter.Operator.EQ);
View Full Code Here

    QuerySelection selection = new QuerySelection(); // SELECT (sum(sales) / 7)
    List<AbstractColumn> columns = Lists.newArrayList();
    columns.add(new AggregationColumn(new SimpleColumn("Sales"), AggregationType.SUM));
    columns.add(new ScalarFunctionColumn(Lists.<AbstractColumn>newArrayList(),
        new Constant(new NumberValue(7))));
    AbstractColumn selectedColumn = new ScalarFunctionColumn(columns, Quotient.getInstance());
    selection.addColumn(selectedColumn);

    query.setSelection(selection);
    QueryGroup group = new QueryGroup();
    group.addColumn(new SimpleColumn("Year"));
View Full Code Here

      QuerySelection completionSelection = new QuerySelection();
      List<AbstractColumn> originalSelectedColumns =
          query.getSelection().getColumns();
      for (int i = 0; i < originalSelectedColumns.size(); i++) {
        AbstractColumn column = originalSelectedColumns.get(i);
        if (query.getGroup().getColumns().contains(column)) {
          completionSelection.addColumn(column);
        } else { // Must be an aggregation column if doesn't appear in the grouping.
          // 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

    assertTrue(completionQuery.hasLabels());
    // Test that labels and formats changed appropriately
    AbstractColumn[] labelColumns =
        completionQuery.getLabels().getColumns().toArray(new AbstractColumn[]{});
    if (labelColumns[1].getId().equals("A")) {
      AbstractColumn tmp = labelColumns[0];
      labelColumns[0] = labelColumns[1];
      labelColumns[1] = tmp;      
    }
    assertEquals(2, labelColumns.length);
    assertEquals("A", labelColumns[0].getId());
    AbstractColumn col = labelColumns[1];
    assertTrue(col instanceof SimpleColumn);
    assertEquals("max-B", ((SimpleColumn) col).getId());
    assertEquals("maxBLabel", completionQuery.getLabels().getLabel(col));
    AbstractColumn[] formatColumns =
        completionQuery.getUserFormatOptions().getColumns().toArray(new AbstractColumn[]{});
    if (formatColumns[1].getId().equals("A")) {
      AbstractColumn tmp = formatColumns[0];
      formatColumns[0] = formatColumns[1];
      formatColumns[1] = tmp;      
    }
    assertEquals(2, formatColumns.length);
    assertEquals("A", formatColumns[0].getId());
View Full Code Here

            QuerySelection completionSelection = new QuerySelection();
            List<AbstractColumn> originalSelectedColumns =
                    query.getSelection().getColumns();
            for(int i = 0; i < originalSelectedColumns.size(); i++) {
                AbstractColumn column = originalSelectedColumns.get(i);
                if(query.getGroup().getColumns().contains(column)) {
                    completionSelection.addColumn(column);
                }
                else { // Must be an aggregation column if doesn't appear in the grouping.
                    // 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) {
View Full Code Here

     * @return a negative integer, zero, or a positive integer as the first
     *         argument is less than, equal to, or greater than the second.
     */
    public int compare(TableRow r1, TableRow r2) {
        for(int i = 0; i < sortColumns.length; i++) {
            AbstractColumn col = sortColumns[i];
            int cc = valueComparator.compare(col.getValue(columnLookup, r1),
                    col.getValue(columnLookup, r2));
            if(cc != 0) {
                return (sortColumnOrder[i] == SortOrder.ASCENDING) ? cc : -cc;
            }
        }
        return 0;
View Full Code Here

TOP

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

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.