Top Description Fields Constructors Methods
org.apache.derby.impl.sql.execute

pack-priv Class CardinalityCounter

extends Object
implements RowLocationRetRowSource
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.store.access.RowLocationRetRowSource, org.apache.derby.iapi.store.access.RowSource
Imports
org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.access.RowLocationRetRowSource, org.apache.derby.iapi.types.DataValueDescriptor, .RowLocation, org.apache.derby.shared.common.sanity.SanityManager

This is a decorator (in Design Patterns Terminology) class to enhance the functionality of a RowLocationRetRowSource. It assumes that the rows are coming in sorted order from the row source and it simply keeps track of the cardinality of all the leading columns.

Field Summary

Modifier and TypeField and Description
private long[]
private long
private DataValueDescriptor[]
private RowLocationRetRowSource

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private DataValueDescriptor[]
public void
closeRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.closeRowSource.

closeRowSource tells the RowSource that it will no longer need to return any rows and it can release any resource it may have.

public long[]

Returns:

an array of unique values.
getCardinality
()

return the array of cardinalities that are kept internally.

public DataValueDescriptor[]
getNextRowFromRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Gets next row from the row source and update the count of unique values that are returned.

public long

Returns:

total rows seen from the row source.
getRowCount
()

get the number of rows seen in the row source thus far.

public FormatableBitSet
getValidColumns()

Implements org.apache.derby.iapi.store.access.RowSource.getValidColumns.

getValidColumns describes the DataValueDescriptor[] returned by all calls to the getNextRowFromRowSource() call.

public void
public boolean
needsRowLocation()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.

public boolean
public boolean
needsToClone()

Implements org.apache.derby.iapi.store.access.RowSource.needsToClone.

Does the caller of getNextRowFromRowSource() need to clone the row in order to keep a reference to the row past the getNextRowFromRowSource() call which returned the row.

public void
public void
rowLocation(RowLocation rl)

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

rowLocation is a callback for the drainer of the row source to return the rowLocation of the current row, i.e, the row that is being returned by getNextRowFromRowSource.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cardinalityback to summary
private long[] cardinality
numRowsback to summary
private long numRows
prevKeyback to summary
private DataValueDescriptor[] prevKey
rowSourceback to summary
private RowLocationRetRowSource rowSource

Constructor Detail

CardinalityCounterback to summary
public CardinalityCounter(RowLocationRetRowSource rowSource)

Method Detail

cloneback to summary
private DataValueDescriptor[] clone(DataValueDescriptor[] clonee)
closeRowSourceback to summary
public void closeRowSource()

Implements org.apache.derby.iapi.store.access.RowSource.closeRowSource.

Doc from org.apache.derby.iapi.store.access.RowSource.closeRowSource.

closeRowSource tells the RowSource that it will no longer need to return any rows and it can release any resource it may have. Subsequent call to any method on the RowSource will result in undefined behavior. A closed rowSource can be closed again.

See Also
RowLocationRetRowSource#closeRowSource
getCardinalityback to summary
public long[] getCardinality()

return the array of cardinalities that are kept internally. One value for each leading key; i.e c1, (c1,c2), (c1,c2,c3) etc.

Returns:long[]

an array of unique values.

getNextRowFromRowSourceback to summary
public DataValueDescriptor[] getNextRowFromRowSource() throws StandardException

Implements org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Gets next row from the row source and update the count of unique values that are returned.

Exceptions
StandardException:

Doc from org.apache.derby.iapi.store.access.RowSource.getNextRowFromRowSource.

Standard Derby Error Policy

See Also
RowLocationRetRowSource#getNextRowFromRowSource
getRowCountback to summary
public long getRowCount()

get the number of rows seen in the row source thus far.

Returns:long

total rows seen from the row source.

getValidColumnsback to summary
public FormatableBitSet getValidColumns()

Implements org.apache.derby.iapi.store.access.RowSource.getValidColumns.

Doc from org.apache.derby.iapi.store.access.RowSource.getValidColumns.

getValidColumns describes the DataValueDescriptor[] returned by all calls to the getNextRowFromRowSource() call. If getValidColumns returns null, the number of columns is given by the DataValueDescriptor.length where DataValueDescriptor[] is returned by the preceeding getNextRowFromRowSource() call. Column N maps to DataValueDescriptor[N], where column numbers start at zero. If getValidColumns return a non null validColumns FormatableBitSet the number of columns is given by the number of bits set in validColumns. Column N is not in the partial row if validColumns.get(N) returns false. Column N is in the partial row if validColumns.get(N) returns true. If column N is in the partial row then it maps to DataValueDescriptor[M] where M is the count of calls to validColumns.get(i) that return true where i < N. If DataValueDescriptor.length is greater than the number of columns indicated by validColumns the extra entries are ignored.

See Also
RowLocationRetRowSource#getValidColumns
keepCountback to summary
public void keepCount(DataValueDescriptor[] currentKey) throws StandardException
needsRowLocationback to summary
public boolean needsRowLocation()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

Doc from org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocation.

needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.

Returns:boolean

true iff this row source expects some row location to be returned

See Also
RowLocationRetRowSource#needsRowLocation
needsRowLocationForDeferredCheckConstraintsback to summary
public boolean needsRowLocationForDeferredCheckConstraints()

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.needsRowLocationForDeferredCheckConstraints.

needsToCloneback to summary
public boolean needsToClone()

Implements org.apache.derby.iapi.store.access.RowSource.needsToClone.

Doc from org.apache.derby.iapi.store.access.RowSource.needsToClone.

Does the caller of getNextRowFromRowSource() need to clone the row in order to keep a reference to the row past the getNextRowFromRowSource() call which returned the row. This call must always return the same for all rows in a RowSource (ie. the caller will call this once per scan from a RowSource and assume the behavior is true for all rows in the RowSource).

See Also
RowLocationRetRowSource#needsToClone
offendingRowLocationback to summary
public void offendingRowLocation(RowLocation rl, long containdId) throws StandardException

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.offendingRowLocation.

rowLocationback to summary
public void rowLocation(RowLocation rl) throws StandardException

Implements org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

Doc from org.apache.derby.iapi.store.access.RowLocationRetRowSource.rowLocation.

rowLocation is a callback for the drainer of the row source to return the rowLocation of the current row, i.e, the row that is being returned by getNextRowFromRowSource. This interface is for the purpose of loading a base table with index. In that case, the indices can be built at the same time the base table is laid down once the row location of the base row is known. This is an example pseudo code on how this call is expected to be used:

		boolean needsRL = rowSource.needsRowLocation();
		DataValueDescriptor[] row;
		while((row = rowSource.getNextRowFromRowSource()) != null)
		{
			RowLocation rl = heapConglomerate.insertRow(row);
			if (needsRL)
				rowSource.rowLocation(rl);
		}
		

NeedsRowLocation and rowLocation will ONLY be called by a drainer of the row source which CAN return a row location. Drainer of row source which cannot return rowLocation will guarantee to not call either callbacks. Conversely, if NeedsRowLocation is called and it returns true, then for every row return by getNextRowFromRowSource, a rowLocation callback must also be issued with the row location of the row. Implementor of both the source and the drain of the row source must be aware of this protocol.
The RowLocation object is own by the caller of rowLocation, in other words, the drainer of the RowSource. This is so that we don't need to new a row location for every row. If the Row Source wants to keep the row location, it needs to clone it (RowLocation is a ClonableObject).
Exceptions
StandardException:
on error
See Also
RowLocationRetRowSource#rowLocation