simpledb.materialize
Class GroupByPlan

java.lang.Object
  extended by simpledb.materialize.GroupByPlan
All Implemented Interfaces:
Plan

public class GroupByPlan
extends Object
implements Plan

The Plan class for the groupby operator.

Author:
Edward Sciore

Constructor Summary
GroupByPlan(Plan p, Collection<String> groupfields, Collection<AggregationFn> aggfns, Transaction tx)
          Creates a groupby plan for the underlying query.
 
Method Summary
 int blocksAccessed()
          Returns the number of blocks required to compute the aggregation, which is one pass through the sorted table.
 int distinctValues(String fldname)
          Returns the number of distinct values for the specified field.
 Scan open()
          This method opens a sort plan for the specified plan.
 int recordsOutput()
          Returns the number of groups.
 Schema schema()
          Returns the schema of the output table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupByPlan

public GroupByPlan(Plan p,
                   Collection<String> groupfields,
                   Collection<AggregationFn> aggfns,
                   Transaction tx)
Creates a groupby plan for the underlying query. The grouping is determined by the specified collection of group fields, and the aggregation is computed by the specified collection of aggregation functions.

Parameters:
p - a plan for the underlying query
groupfields - the group fields
aggfns - the aggregation functions
tx - the calling transaction
Method Detail

open

public Scan open()
This method opens a sort plan for the specified plan. The sort plan ensures that the underlying records will be appropriately grouped.

Specified by:
open in interface Plan
Returns:
a scan
See Also:
Plan.open()

blocksAccessed

public int blocksAccessed()
Returns the number of blocks required to compute the aggregation, which is one pass through the sorted table. It does not include the one-time cost of materializing and sorting the records.

Specified by:
blocksAccessed in interface Plan
Returns:
the estimated number of block accesses
See Also:
Plan.blocksAccessed()

recordsOutput

public int recordsOutput()
Returns the number of groups. Assuming equal distribution, this is the product of the distinct values for each grouping field.

Specified by:
recordsOutput in interface Plan
Returns:
the estimated number of output records
See Also:
Plan.recordsOutput()

distinctValues

public int distinctValues(String fldname)
Returns the number of distinct values for the specified field. If the field is a grouping field, then the number of distinct values is the same as in the underlying query. If the field is an aggregate field, then we assume that all values are distinct.

Specified by:
distinctValues in interface Plan
Parameters:
fldname - the name of a field
Returns:
the estimated number of distinct field values in the output
See Also:
Plan.distinctValues(java.lang.String)

schema

public Schema schema()
Returns the schema of the output table. The schema consists of the group fields, plus one field for each aggregation function.

Specified by:
schema in interface Plan
Returns:
the query's schema
See Also:
Plan.schema()


Copyright © 2011. All Rights Reserved.