CountNullableAggComputer Class Reference

CountNullableAggComputer computes COUNT(X), which does not count tuples for which X IS NULL. More...

#include <AggComputerImpl.h>

Inheritance diagram for CountNullableAggComputer:

CountAggComputer AggComputer List of all members.

Public Member Functions

virtual void clearAccumulator (TupleDatum &accumulatorDatum)
 Clears an accumulator.
virtual void updateAccumulator (TupleDatum &accumulatorDatum, TupleData const &inputTuple)
 Updates an accumulator with a new input tuple.
virtual void initAccumulator (TupleDatum &accumulatorDatumDest, TupleData const &inputTuple)
 Initializes a new accumulator datum from an input tuple.
virtual void initAccumulator (TupleDatum &accumulatorDatumSrc, TupleDatum &accumulatorDatumDest)
 Initializes a new accumulator datum from an existing accumulator datum.
virtual void updateAccumulator (TupleDatum &accumulatorDatumSrc, TupleDatum &accumulatorDatumDest, TupleData const &inputTuple)
 Computes a new accumulator from an existing accumulator dataum and a new input tuple.
virtual void computeOutput (TupleDatum &outputDatum, TupleDatum const &accumulatorDatum)
 Computes an output based on accumulator state.
virtual void setInputAttrIndex (uint iInputAttrIndex)
 Sets the attribute index from which this computer should read input values in source tuples.

Static Public Member Functions

static AggComputernewAggComputer (AggFunction aggFunction, TupleAttributeDescriptor const *pAttrDesc)
 Virtual constructor.

Protected Member Functions

uint64_tinterpretDatum (TupleDatum &)
void clearAccumulatorImpl (TupleDatum &accumulatorDatum)
void initAccumulatorImpl (TupleDatum &accumulatorDatum)
void updateAccumulatorImpl (TupleDatum &accumulatorDatum)

Protected Attributes

int iInputAttr

Detailed Description

CountNullableAggComputer computes COUNT(X), which does not count tuples for which X IS NULL.

Definition at line 89 of file AggComputerImpl.h.


Member Function Documentation

void CountNullableAggComputer::clearAccumulator ( TupleDatum accumulatorDatum  )  [virtual]

Clears an accumulator.

Parameters:
accumulatorDatum in-memory value to be cleared

Implements AggComputer.

Definition at line 169 of file AggComputer.cpp.

References CountAggComputer::clearAccumulatorImpl().

00170 {
00171     clearAccumulatorImpl(accumulatorDatum);
00172 }

void CountNullableAggComputer::updateAccumulator ( TupleDatum accumulatorDatum,
TupleData const &  inputTuple 
) [virtual]

Updates an accumulator with a new input tuple.

Parameters:
accumulatorDatum in-memory value to be updated
inputTuple source for update; no references to this data should be retained after this method returns

Implements AggComputer.

Definition at line 174 of file AggComputer.cpp.

References AggComputer::iInputAttr, TupleDatum::pData, and CountAggComputer::updateAccumulatorImpl().

00177 {
00178     assert(iInputAttr != -1);
00179     TupleDatum const &inputDatum = inputTuple[iInputAttr];
00180     if (inputDatum.pData) {
00181         updateAccumulatorImpl(accumulatorDatum);
00182     }
00183 }

void CountNullableAggComputer::initAccumulator ( TupleDatum accumulatorDatumDest,
TupleData const &  inputTuple 
) [virtual]

Initializes a new accumulator datum from an input tuple.

Parameters:
accumulatorDatumDest in-memory value to be updated. Memory needs to be associated with this datum by the caller.
inputTuple source for update; no references to this data should be retained after this method returns

Implements AggComputer.

Definition at line 185 of file AggComputer.cpp.

References CountAggComputer::clearAccumulatorImpl(), AggComputer::iInputAttr, CountAggComputer::initAccumulatorImpl(), and TupleDatum::pData.

00188 {
00189     assert(iInputAttr != -1);
00190     TupleDatum const &inputDatum = inputTuple[iInputAttr];
00191     if (inputDatum.pData) {
00192         initAccumulatorImpl(accumulatorDatum);
00193     } else {
00194         clearAccumulatorImpl(accumulatorDatum);
00195     }
00196 }

void CountNullableAggComputer::initAccumulator ( TupleDatum accumulatorDatumSrc,
TupleDatum accumulatorDatumDest 
) [virtual]

Initializes a new accumulator datum from an existing accumulator datum.

Parameters:
accumulatorDatumSrc the existing accumulator datum
accumulatorDatumDest the new accumulator datum. Memory needs to be associated with this datum by the caller.

Implements AggComputer.

Definition at line 198 of file AggComputer.cpp.

References TupleDatum::memCopyFrom().

00201 {
00202     accumulatorDatumDest.memCopyFrom(accumulatorDatumSrc);
00203 }

void CountNullableAggComputer::updateAccumulator ( TupleDatum accumulatorDatumSrc,
TupleDatum accumulatorDatumDest,
TupleData const &  inputTuple 
) [virtual]

Computes a new accumulator from an existing accumulator dataum and a new input tuple.

Parameters:
accumulatorDatumSrc the existing accumulator datum
accumulatorDatumDest the new accumulator datum. memory needs to be associated with this datum by the caller.
inputTuple source for update; no references to this data should be retained after this method returns

Implements AggComputer.

Definition at line 205 of file AggComputer.cpp.

References TupleDatum::copyFrom(), AggComputer::iInputAttr, TupleDatum::pData, and CountAggComputer::updateAccumulatorImpl().

00209 {
00210     assert(iInputAttr != -1);
00211     TupleDatum const &inputDatum = inputTuple[iInputAttr];
00212     if (inputDatum.pData) {
00213         updateAccumulatorImpl(accumulatorDatumSrc);
00214     }
00215     /*
00216      * For count, accumulatorDatumSrc can accomodate the updated value so
00217      * there is no need to use memCopyFrom.
00218      */
00219     accumulatorDatumDest.copyFrom(accumulatorDatumSrc);
00220 }

uint64_t & CountAggComputer::interpretDatum ( TupleDatum  )  [inline, protected, inherited]

Definition at line 94 of file AggComputer.cpp.

References TupleDatum::cbData, and TupleDatum::pData.

Referenced by CountAggComputer::clearAccumulatorImpl(), CountAggComputer::initAccumulatorImpl(), and CountAggComputer::updateAccumulatorImpl().

00095 {
00096     assert(datum.cbData == sizeof(uint64_t));
00097     assert(datum.pData);
00098     return *reinterpret_cast<uint64_t *>(const_cast<PBuffer>(datum.pData));
00099 }

void CountAggComputer::clearAccumulatorImpl ( TupleDatum accumulatorDatum  )  [inline, protected, inherited]

Definition at line 101 of file AggComputer.cpp.

References count(), and CountAggComputer::interpretDatum().

Referenced by clearAccumulator(), CountStarAggComputer::clearAccumulator(), and initAccumulator().

00102 {
00103     uint64_t &count = interpretDatum(accumulatorDatum);
00104     count = 0;
00105 }

void CountAggComputer::initAccumulatorImpl ( TupleDatum accumulatorDatum  )  [inline, protected, inherited]

Definition at line 107 of file AggComputer.cpp.

References count(), and CountAggComputer::interpretDatum().

Referenced by initAccumulator(), and CountStarAggComputer::initAccumulator().

00108 {
00109     uint64_t &count = interpretDatum(accumulatorDatum);
00110     count = 1;
00111 }

void CountAggComputer::updateAccumulatorImpl ( TupleDatum accumulatorDatum  )  [inline, protected, inherited]

Definition at line 113 of file AggComputer.cpp.

References count(), and CountAggComputer::interpretDatum().

Referenced by updateAccumulator(), and CountStarAggComputer::updateAccumulator().

00115 {
00116     uint64_t &count = interpretDatum(accumulatorDatum);
00117     ++count;
00118 }

void CountAggComputer::computeOutput ( TupleDatum outputDatum,
TupleDatum const &  accumulatorDatum 
) [virtual, inherited]

Computes an output based on accumulator state.

Parameters:
outputDatum receives reference to computed output in preparation for marshalling result
accumulatorDatum final in-memory accumulator state

Implements AggComputer.

Definition at line 120 of file AggComputer.cpp.

00123 {
00124     // Set output to alias accumulator value directly.
00125     outputDatum = accumulatorDatum;
00126 }

AggComputer * AggComputer::newAggComputer ( AggFunction  aggFunction,
TupleAttributeDescriptor const *  pAttrDesc 
) [static, inherited]

Virtual constructor.

Parameters:
aggFunction function for which to construct a computer
pAttrDesc descriptor for input attribute, or NULL for no input attribute (as in COUNT(*))

Definition at line 34 of file AggComputer.cpp.

References AGG_FUNC_COUNT, AGG_FUNC_MAX, AGG_FUNC_MIN, AGG_FUNC_SINGLE_VALUE, AGG_FUNC_SUM, STANDARD_TYPE_DOUBLE, STANDARD_TYPE_INT_16, STANDARD_TYPE_INT_32, STANDARD_TYPE_INT_64, STANDARD_TYPE_INT_8, STANDARD_TYPE_REAL, STANDARD_TYPE_UINT_16, STANDARD_TYPE_UINT_32, STANDARD_TYPE_UINT_64, and STANDARD_TYPE_UINT_8.

Referenced by SortedAggExecStream::newAggComputer(), and LhxAggExecStream::setAggComputers().

00037 {
00038     switch (aggFunction) {
00039     case AGG_FUNC_COUNT:
00040         if (pAttrDesc) {
00041             return new CountNullableAggComputer();
00042         } else {
00043             return new CountStarAggComputer();
00044         }
00045     case AGG_FUNC_SUM:
00046         assert(pAttrDesc);
00047         // TODO jvs 6-Oct-2005:  gotta use some of that template
00048         // metaprogramming mumbo jumbo to get rid of this
00049         switch (pAttrDesc->pTypeDescriptor->getOrdinal()) {
00050         case STANDARD_TYPE_INT_8:
00051             return new SumAggComputer<int8_t>();
00052         case STANDARD_TYPE_UINT_8:
00053             return new SumAggComputer<uint8_t>();
00054         case STANDARD_TYPE_INT_16:
00055             return new SumAggComputer<int16_t>();
00056         case STANDARD_TYPE_UINT_16:
00057             return new SumAggComputer<uint16_t>();
00058         case STANDARD_TYPE_INT_32:
00059             return new SumAggComputer<int32_t>();
00060         case STANDARD_TYPE_UINT_32:
00061             return new SumAggComputer<uint32_t>();
00062         case STANDARD_TYPE_INT_64:
00063             return new SumAggComputer<int64_t>();
00064         case STANDARD_TYPE_UINT_64:
00065             return new SumAggComputer<uint64_t>();
00066         case STANDARD_TYPE_REAL:
00067             return new SumAggComputer<float>();
00068         case STANDARD_TYPE_DOUBLE:
00069             return new SumAggComputer<double>();
00070         }
00071     case AGG_FUNC_MIN:
00072     case AGG_FUNC_MAX:
00073     case AGG_FUNC_SINGLE_VALUE:
00074         assert(pAttrDesc);
00075         return new ExtremeAggComputer(aggFunction, *pAttrDesc);
00076     }
00077     permAssert(false);
00078 }

void AggComputer::setInputAttrIndex ( uint  iInputAttrIndex  )  [virtual, inherited]

Sets the attribute index from which this computer should read input values in source tuples.

Parameters:
iInputAttrIndex 0-based tuple attribute index

Reimplemented in LbmRepeatingAggComputer.

Definition at line 85 of file AggComputer.cpp.

References AggComputer::iInputAttr.

Referenced by LbmRepeatingAggComputer::setInputAttrIndex().

00086 {
00087     iInputAttr = iInputAttrInit;
00088 }


Member Data Documentation

int AggComputer::iInputAttr [protected, inherited]

Definition at line 50 of file AggComputer.h.

Referenced by AggComputer::AggComputer(), CountStarAggComputer::clearAccumulator(), SumAggComputer< T >::initAccumulator(), ExtremeAggComputer::initAccumulator(), initAccumulator(), CountStarAggComputer::initAccumulator(), AggComputer::setInputAttrIndex(), SumAggComputer< T >::updateAccumulator(), ExtremeAggComputer::updateAccumulator(), and updateAccumulator().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:29 2009 for Fennel by  doxygen 1.5.1