com.google.visualization.datasource.query.engine
Class TableAggregator

java.lang.Object
  extended by com.google.visualization.datasource.query.engine.TableAggregator

public class TableAggregator
extends java.lang.Object

Aggregates a DataTable according to specific row groups. The groups are defined by an ordered list of group-by columns. For instance, if the list is {"Name", "Revenue"} then each unique pair of values of these columns (e.g., {"John", 300}, {"John", 19}, {"Sarah", 2222}) defines a group, where the group includes all of the rows that share the values defined by the pair (for example all the rows where value("Name") = "John" and value("Cost") = 300). In addition there is a group for each unique name ({"John"}, {"Sarah"}) and an additional group that contains all the rows in the table. The groups described above are kept in an aggregation tree. The root of the tree contains aggregation information for the group of all rows. Each level of the tree (except for the root level) is associated with an aggregation column. Each node of the tree is associated with a value (of some cell in the column defining the node's level). A path in the tree from the root to a node is represented by an ordered list of values, and is associated with the group of data rows identified by this list. In our example the tree contains one path of length 0 ({}), two paths of length 1 ({"John"}, {"Sarah"}), and three paths of length two ({"John", 300}, {"John", 19}, {"Sarah", 2222}). The aggregation data stored is all aggregation data possible for the columns to aggregate (also called aggregation columns): the minimum, maximum, count, average, and sum, each of these where applicable.

Author:
Yoav G.

Constructor Summary
TableAggregator(java.util.List<java.lang.String> groupByColumns, java.util.Set<java.lang.String> aggregateColumns, DataTable table)
          Constructs a table aggregator and aggregates the table.
 
Method Summary
 Value getAggregationValue(AggregationPath path, java.lang.String columnId, AggregationType type)
          Returns the aggregation value of a specific column and type.
 java.util.Set<AggregationPath> getPathsToLeaves()
          Returns a set containing the paths to all the leaves in the tree.
 AggregationPath getRowPath(TableRow row, DataTable table, int depth)
          Creates a path for the aggregation tree defined by a table row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableAggregator

public TableAggregator(java.util.List<java.lang.String> groupByColumns,
                       java.util.Set<java.lang.String> aggregateColumns,
                       DataTable table)
Constructs a table aggregator and aggregates the table.

Parameters:
groupByColumns - An ordered list of columns to group by.
aggregateColumns - A set of columns to aggregate.
table - The table.
Method Detail

getRowPath

public AggregationPath getRowPath(TableRow row,
                                  DataTable table,
                                  int depth)
Creates a path for the aggregation tree defined by a table row.

Parameters:
row - The table row.
table - The table.
depth - The depth of the desired path.
Returns:
A path for the aggregation tree defined by the table row.

getPathsToLeaves

public java.util.Set<AggregationPath> getPathsToLeaves()
Returns a set containing the paths to all the leaves in the tree.

Returns:
A set containing the paths to all the leaves in the tree.

getAggregationValue

public Value getAggregationValue(AggregationPath path,
                                 java.lang.String columnId,
                                 AggregationType type)
Returns the aggregation value of a specific column and type.

Parameters:
path - The aggregation path.
columnId - The requested column id.
type - The requested aggregation type.
Returns:
The aggregation values of a specific column.


Copyright © 2009 Google. All Rights Reserved.