Class CardinalityCounter
java.lang.Object
org.apache.derby.impl.sql.execute.CardinalityCounter
- All Implemented Interfaces:
RowLocationRetRowSource
,RowSource
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
FieldsModifier and TypeFieldDescriptionprivate long[]
private long
private DataValueDescriptor[]
private RowLocationRetRowSource
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate DataValueDescriptor[]
clone
(DataValueDescriptor[] clonee) void
closeRowSource tells the RowSource that it will no longer need to return any rows and it can release any resource it may have.long[]
return the array of cardinalities that are kept internally.Gets next row from the row source and update the count of unique values that are returned.long
get the number of rows seen in the row source thus far.getValidColumns describes the DataValueDescriptor[] returned by all calls to the getNextRowFromRowSource() call.void
keepCount
(DataValueDescriptor[] currentKey) boolean
needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.boolean
boolean
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.void
offendingRowLocation
(RowLocation rl, long containdId) void
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.
-
Field Details
-
rowSource
-
prevKey
-
cardinality
private long[] cardinality -
numRows
private long numRows
-
-
Constructor Details
-
CardinalityCounter
-
-
Method Details
-
needsRowLocation
public boolean needsRowLocation()Description copied from interface:RowLocationRetRowSource
needsRowLocation returns true iff this the row source expects the drainer of the row source to call rowLocation after getting a row from getNextRowFromRowSource.- Specified by:
needsRowLocation
in interfaceRowLocationRetRowSource
- Returns:
- true iff this row source expects some row location to be returned
- See Also:
-
needsRowLocationForDeferredCheckConstraints
public boolean needsRowLocationForDeferredCheckConstraints()- Specified by:
needsRowLocationForDeferredCheckConstraints
in interfaceRowLocationRetRowSource
-
offendingRowLocation
- Specified by:
offendingRowLocation
in interfaceRowLocationRetRowSource
- Throws:
StandardException
-
rowLocation
Description copied from interface:RowLocationRetRowSource
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).- Specified by:
rowLocation
in interfaceRowLocationRetRowSource
- Throws:
StandardException
- on error- See Also:
-
getNextRowFromRowSource
Gets next row from the row source and update the count of unique values that are returned.- Specified by:
getNextRowFromRowSource
in interfaceRowSource
- Throws:
StandardException
- Standard Derby Error Policy- See Also:
-
needsToClone
public boolean needsToClone()Description copied from interface:RowSource
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).- Specified by:
needsToClone
in interfaceRowSource
- See Also:
-
getValidColumns
Description copied from interface:RowSource
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.- Specified by:
getValidColumns
in interfaceRowSource
- See Also:
-
closeRowSource
public void closeRowSource()Description copied from interface:RowSource
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.- Specified by:
closeRowSource
in interfaceRowSource
- See Also:
-
clone
-
keepCount
- Throws:
StandardException
-
getCardinality
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:
- an array of unique values.
-
getRowCount
public long getRowCount()get the number of rows seen in the row source thus far.- Returns:
- total rows seen from the row source.
-