simpledb.materialize
Class GroupByScan

java.lang.Object
  extended by simpledb.materialize.GroupByScan
All Implemented Interfaces:
Scan

public class GroupByScan
extends Object
implements Scan

The Scan class for the groupby operator.

Author:
Edward Sciore

Constructor Summary
GroupByScan(Scan s, Collection<String> groupfields, Collection<AggregationFn> aggfns)
          Creates a groupby scan, given a grouped table scan.
 
Method Summary
 void beforeFirst()
          Positions the scan before the first group.
 void close()
          Closes the scan by closing the underlying scan.
 int getInt(String fldname)
          Gets the integer value of the specified field.
 String getString(String fldname)
          Gets the string value of the specified field.
 Constant getVal(String fldname)
          Gets the Constant value of the specified field.
 boolean hasField(String fldname)
          Returns true if the scan has the specified field.
 boolean next()
          Moves to the next group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupByScan

public GroupByScan(Scan s,
                   Collection<String> groupfields,
                   Collection<AggregationFn> aggfns)
Creates a groupby scan, given a grouped table scan.

Parameters:
s - the grouped scan
groupfields - the group fields
aggfns - the aggregation functions
Method Detail

beforeFirst

public void beforeFirst()
Positions the scan before the first group. Internally, the underlying scan is always positioned at the first record of a group, which means that this method moves to the first underlying record.

Specified by:
beforeFirst in interface Scan
See Also:
Scan.beforeFirst()

next

public boolean next()
Moves to the next group. The key of the group is determined by the group values at the current record. The method repeatedly reads underlying records until it encounters a record having a different key. The aggregation functions are called for each record in the group. The values of the grouping fields for the group are saved.

Specified by:
next in interface Scan
Returns:
false if there is no next record
See Also:
Scan.next()

close

public void close()
Closes the scan by closing the underlying scan.

Specified by:
close in interface Scan
See Also:
Scan.close()

getVal

public Constant getVal(String fldname)
Gets the Constant value of the specified field. If the field is a group field, then its value can be obtained from the saved group value. Otherwise, the value is obtained from the appropriate aggregation function.

Specified by:
getVal in interface Scan
Parameters:
fldname - the name of the field
Returns:
the value of that field, expressed as a Constant.
See Also:
Scan.getVal(java.lang.String)

getInt

public int getInt(String fldname)
Gets the integer value of the specified field. If the field is a group field, then its value can be obtained from the saved group value. Otherwise, the value is obtained from the appropriate aggregation function.

Specified by:
getInt in interface Scan
Parameters:
fldname - the name of the field
Returns:
the field's integer value in the current record
See Also:
Scan.getVal(java.lang.String)

getString

public String getString(String fldname)
Gets the string value of the specified field. If the field is a group field, then its value can be obtained from the saved group value. Otherwise, the value is obtained from the appropriate aggregation function.

Specified by:
getString in interface Scan
Parameters:
fldname - the name of the field
Returns:
the field's string value in the current record
See Also:
Scan.getVal(java.lang.String)

hasField

public boolean hasField(String fldname)
Description copied from interface: Scan
Returns true if the scan has the specified field.

Specified by:
hasField in interface Scan
Parameters:
fldname - the name of the field
Returns:
true if the scan has that field


Copyright © 2011. All Rights Reserved.