Class CardinalityCounter

  • All Implemented Interfaces:
    RowLocationRetRowSource, RowSource

    class CardinalityCounter
    extends java.lang.Object
    implements RowLocationRetRowSource
    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.
    • Method Detail

      • rowLocation

        public void rowLocation​(RowLocation rl)
                         throws StandardException
        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 interface RowLocationRetRowSource
        Throws:
        StandardException - on error
        See Also:
        RowLocationRetRowSource.rowLocation(org.apache.derby.iapi.types.RowLocation)
      • 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 interface RowSource
        See Also:
        RowSource.needsToClone()
      • getValidColumns

        public FormatableBitSet 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 interface RowSource
        See Also:
        RowSource.getValidColumns()
      • 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 interface RowSource
        See Also:
        RowSource.closeRowSource()
      • 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.