Package com.google.visualization.datasource.datatable

Examples of com.google.visualization.datasource.datatable.TableRow


    colIds.add("col4");
    colIds.add("col5");

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    row.addCell(new TableCell(new DateValue(2001, 10, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 10, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("ccc"));
    row.addCell(new TableCell(111));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2001, 1, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 30, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(1000, 11, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("bbb"));
    row.addCell(new TableCell(3));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2012, 2, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 3, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 1, 1, 1, 10, 31, 4)));
    rows.add(row);

    row = new TableRow();
    row.addCell("ddd");
    row.addCell(222);
    row.addCell(false);
    row.addCell(new DateValue(1997, 5, 5));
    row.addCell(new TimeOfDayValue(12, 15, 15, 14));
    row.addCell(new DateTimeValue(3100, 1, 2, 15, 15, 1, 0));
    rows.add(row);

    testData.addRows(rows);
  }
View Full Code Here


    testData.addColumn(c1);
    testData.addColumn(c2);

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(new NumberValue(222), "222"));
    row.addCell(new TableCell(false));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(""));
    row.addCell(new TableCell(NumberValue.getNullValue()));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new TextValue("bbb"), "bbb"));
    row.addCell(new TableCell(333));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("d'dd"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    rows.add(row);

    testData.addRows(rows);
    assertEquals(
        "{\"cols\":[{\"id\":\"A\",\"label\":\"col0\",\"type\":\"string\",\"pattern\":\"\"},"
View Full Code Here

    testData.addColumn(c1);
    testData.addColumn(c2);

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 1), "1/1/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 1, 0, 0, 0, 0), "1/1/2011 00:00:00"));
    row.addCell(new TableCell(new NumberValue(222), "222"));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 2), "1/2/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 2, 3, 15, 0, 0)));
    row.addCell(new TableCell(NumberValue.getNullValue()));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 3), "1/3/2011"));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 3, 3, 15, 0, 0), "1/1/2011 03:15:00"));
    row.addCell(new TableCell(333));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new DateValue(2011, 1, 4)));
    row.addCell(new TableCell(new DateTimeValue(2011, 1, 4, 0, 0, 0, 0)));
    row.addCell(new TableCell(222));
    rows.add(row);
   
    testData.addRows(rows);
    assertEquals(
        "{\"cols\":[{\"id\":\"DateA\",\"label\":\"col0\",\"type\":\"date\",\"pattern\":\"\"},"
View Full Code Here

    testData.addColumn(c0);
    testData.addColumn(c1);

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(new NumberValue(222), "$222"));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("bbb"));
    row.addCell(new TableCell(new NumberValue(333)));
    rows.add(row);

    testData.addRows(rows);
    testData.addWarning(new Warning(ReasonType.DATA_TRUNCATED, "Sorry, data truncated"));
    testData.addWarning(new Warning(ReasonType.NOT_SUPPORTED, "foobar"));
View Full Code Here

*
* @author Yonatan B.Y.
*/
public class CompoundFilterTest extends TestCase {
  public void testAndFilter() {
    TableRow trueRow = new TableRow();
    trueRow.addCell(new TableCell("a"));
    trueRow.addCell(new TableCell(123));
    trueRow.addCell(new TableCell("a"));
    TableRow falseRow = new TableRow();
    falseRow.addCell(new TableCell("a"));
    falseRow.addCell(new TableCell(123));
    falseRow.addCell(new TableCell("b"));

    DataTable table = new DataTable();
    table.addColumn(new ColumnDescription("c1", ValueType.TEXT, "c1"));
    table.addColumn(new ColumnDescription("c2", ValueType.TEXT, "c2"));
    table.addColumn(new ColumnDescription("c3", ValueType.TEXT, "c3"));
View Full Code Here

    assertTrue(compoundFilter.isMatch(table, trueRow));
    assertFalse(compoundFilter.isMatch(table, falseRow));
  }

  public void testOrFilter() {
    TableRow falseRow = new TableRow();
    falseRow.addCell(new TableCell("a"));
    falseRow.addCell(new TableCell(123));
    falseRow.addCell(new TableCell("a"));
    TableRow trueRow = new TableRow();
    trueRow.addCell(new TableCell("a"));
    trueRow.addCell(new TableCell(123));
    trueRow.addCell(new TableCell("b"));

    DataTable table = new DataTable();
    table.addColumn(new ColumnDescription("c1", ValueType.TEXT, "c1"));
    table.addColumn(new ColumnDescription("c2", ValueType.TEXT, "c2"));
    table.addColumn(new ColumnDescription("c3", ValueType.TEXT, "c3"));
View Full Code Here

    DataTable result = new DataTable();
    result.addColumns(newColumnDescriptions);

    // Calculate the values in the data table rows.
    for (TableRow sourceRow : table.getRows()) {
      TableRow newRow = new TableRow();
      for (AbstractColumn col : selectedColumns) {
        boolean wasFound = false;
        Set<List<Value>> pivotValuesSet = columnLookups.keySet();
        for (List<Value> values : pivotValuesSet) {
          // If the current column-lookup contains the current column and it is
          // either a column that contains aggregations or a column that
          // contains only group-by columns and was not yet found, get its value
          // in the current row. Otherwise continue. If the column contains
          // only group-by columns it should appear only once, even though
          // it may appear in many column lookups.
          if (columnLookups.get(values).containsColumn(col)
              && ((col.getAllAggregationColumns().size() != 0) || !wasFound)) {
            wasFound = true;
            newRow.addCell(sourceRow.getCell(columnLookups.get(values).getColumnIndex(col)));
          }
        }
        // If the column was not found in any of the column lookups
        // calculate its value (e.g., scalar function column that was not
        // calculated in a previous stage).
        if (!wasFound) {
          DataTableColumnLookup lookup = new DataTableColumnLookup(table);
          newRow.addCell(col.getCell(lookup, sourceRow));
        }
      }
      result.addRow(newRow);
    }
    return result;
View Full Code Here

    tempTable.addColumns(newColumnDescriptions);

    // Calculate the values of the added scalar function columns in each row.
    DataTableColumnLookup lookup = new DataTableColumnLookup(table);
    for (TableRow sourceRow : table.getRows()) {
      TableRow newRow = new TableRow();
      for (TableCell sourceCell : sourceRow.getCells()) {
        newRow.addCell(sourceCell);
      }
      for (ScalarFunctionColumn column : groupAndPivotScalarFunctionColumns) {
        newRow.addCell(new TableCell(column.getValue(lookup, sourceRow)));
      }
      try {
        tempTable.addRow(newRow);
      } catch (TypeMismatchException e) {
        // Should not happen, given that the original table is OK.
      }
    }
    table = tempTable;

    // Calculate the aggregations.
    TableAggregator aggregator = new TableAggregator(groupAndPivotIds,
        Sets.newHashSet(aggregationIds), table);
    Set<AggregationPath> paths = aggregator.getPathsToLeaves();

    // These variables will hold the "titles" of the rows and columns.
    // They are TreeSets because their order matters.
    SortedSet<RowTitle> rowTitles =
        Sets.newTreeSet(GroupingComparators.ROW_TITLE_COMPARATOR);
    SortedSet<ColumnTitle> columnTitles = Sets.newTreeSet(
        GroupingComparators.getColumnTitleDynamicComparator(columnAggregations));

    // A tree set containing all pivot value lists (the set is for the
    // uniqueness and the tree for the order).
    TreeSet<List<Value>> pivotValuesSet =
        Sets.newTreeSet(GroupingComparators.VALUE_LIST_COMPARATOR);
    // This MetaTable holds all the data in the table, this data is then
    // dumped into the real table.
    MetaTable metaTable = new MetaTable();
    for (AggregationColumn columnAggregation : columnAggregations) {
      for (AggregationPath path : paths) {

        // A ColumnTitle is composed of all the values for the pivot-by
        // columns, and a ColumnAggregation. That is why it is necessary to iterate over all
        // ColumnAggregations and create a ColumnTitle for each one.
        List<Value> originalValues = path.getValues();

        // Separate originalValues into the rowValues and columnValues. The
        // rowValues are the values of the group-by columns and the columnValues
        // are the values of the pivot-by columns.
        List<Value> rowValues = originalValues.subList(0, groupByIds.size());
        RowTitle rowTitle = new RowTitle(rowValues);
        rowTitles.add(rowTitle);

        List<Value> columnValues = originalValues.subList(groupByIds.size(), originalValues.size());
        pivotValuesSet.add(columnValues);

        ColumnTitle columnTitle = new ColumnTitle(columnValues,
            columnAggregation, (columnAggregations.size() > 1));
        columnTitles.add(columnTitle);
        metaTable.put(rowTitle, columnTitle, new TableCell(aggregator.getAggregationValue(path,
            columnAggregation.getAggregatedColumn().getId(),
            columnAggregation.getAggregationType())));
      }
    }

    // Create the scalar function column titles for the scalar function columns
    // that contain aggregations.
    List<ScalarFunctionColumnTitle> scalarFunctionColumnTitles =
        Lists.newArrayList();
    for (ScalarFunctionColumn scalarFunctionColumn :
        selectedScalarFunctionColumns) {
      if (scalarFunctionColumn.getAllAggregationColumns().size() != 0) {
        for (List<Value> columnValues : pivotValuesSet) {
          scalarFunctionColumnTitles.add(new ScalarFunctionColumnTitle(columnValues,
              scalarFunctionColumn));
        }
      }
    }

    // Create the new table description.
    DataTable result = createDataTable(groupByIds, columnTitles, table, scalarFunctionColumnTitles);
    List<ColumnDescription> colDescs = result.getColumnDescriptions();

    // Fill the columnIndices and columnLookups parameters for the group-by
    // columns and the aggregation columns.
    columnIndices.clear();
    int columnIndex = 0;
    if (group != null) {
      List<Value> empytListOfValues = Lists.newArrayList();
      columnLookups.put(empytListOfValues, new GenericColumnLookup());
      for (AbstractColumn column : group.getColumns()) {
        columnIndices.put(column, columnIndex);
        if (!(column instanceof ScalarFunctionColumn)) {
          ((GenericColumnLookup) columnLookups.get(empytListOfValues)).put(column, columnIndex);
          for (List<Value> columnValues : pivotValuesSet) {
            if (!columnLookups.containsKey(columnValues)) {
              columnLookups.put(columnValues, new GenericColumnLookup());
            }
            ((GenericColumnLookup) columnLookups.get(columnValues)).put(column, columnIndex);
          }
        }
        columnIndex++;
      }
    }

    for (ColumnTitle title : columnTitles) {
      columnIndices.put(title.aggregation, columnIndex);
      List<Value> values = title.getValues();
      if (!columnLookups.containsKey(values)) {
        columnLookups.put(values, new GenericColumnLookup());
      }
      ((GenericColumnLookup) columnLookups.get(values)).put(title.aggregation, columnIndex);
      columnIndex++;
    }

    // Dump the data from the metaTable to the result DataTable.
    for (RowTitle rowTitle : rowTitles) {
      TableRow curRow = new TableRow();
      // Add the group-by columns cells.
      for (Value v : rowTitle.values) {
        curRow.addCell(new TableCell(v));
      }
      Map<ColumnTitle, TableCell> rowData = metaTable.getRow(rowTitle);
      int i = 0;
      // Add the aggregation columns cells.
      for (ColumnTitle colTitle : columnTitles) {
        TableCell cell = rowData.get(colTitle);
        curRow.addCell((cell != null) ? cell : new TableCell(
            Value.getNullValueFromValueType(colDescs.get(i + rowTitle.values.size()).getType())));
        i++;
      }
      // Add the scalar function columns cells.
      for (ScalarFunctionColumnTitle columnTitle : scalarFunctionColumnTitles) {
        curRow.addCell(new TableCell(columnTitle.scalarFunctionColumn.
            getValue(columnLookups.get(columnTitle.getValues()), curRow)));
      }
      result.addRow(curRow);
    }
View Full Code Here

    colIds.add("col4");
    colIds.add("col5");

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    row.addCell(new TableCell(new DateValue(2001, 10, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 10, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("ccc"));
    row.addCell(new TableCell(111));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2001, 1, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 30, 13, 14)));
    row.addCell(new TableCell(new DateTimeValue(1000, 11, 1, 1, 10, 23, 432)));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("bbb"));
    row.addCell(new TableCell(3));
    row.addCell(new TableCell(true));
    row.addCell(new TableCell(new DateValue(2012, 2, 14)));
    row.addCell(new TableCell(new TimeOfDayValue(12, 11, 3, 14)));
    row.addCell(new TableCell(new DateTimeValue(2000, 1, 1, 1, 10, 31, 4)));
    rows.add(row);

    row = new TableRow();
    row.addCell("ddd");
    row.addCell(222);
    row.addCell(false);
    row.addCell(new DateValue(1997, 5, 5));
    row.addCell(new TimeOfDayValue(12, 15, 15, 14));
    row.addCell(new DateTimeValue(3100, 1, 2, 15, 15, 1, 0));
    rows.add(row);

    testData.addRows(rows);
  }
View Full Code Here

    testData.addColumn(c1);
    testData.addColumn(c2);

    rows = Lists.newArrayList();

    TableRow row = new TableRow();
    row.addCell(new TableCell("aaa"));
    row.addCell(new TableCell(new NumberValue(222), "222"));
    row.addCell(new TableCell(false));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(""));
    row.addCell(new TableCell(NumberValue.getNullValue()));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell(new TextValue("bbb"), "bb@@b"));
    row.addCell(new TableCell(333));
    row.addCell(new TableCell(true));
    rows.add(row);

    row = new TableRow();
    row.addCell(new TableCell("ddd"));
    row.addCell(new TableCell(222));
    row.addCell(new TableCell(false));
    rows.add(row);

    testData.addRows(rows);

    assertEquals(
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.TableRow

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.