#include <AggComputerImpl.h>
Inheritance diagram for SumAggComputer< T >:
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 | computeOutput (TupleDatum &outputDatum, TupleDatum const &accumulatorDatum) |
Computes an output based on accumulator state. | |
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 | setInputAttrIndex (uint iInputAttrIndex) |
Sets the attribute index from which this computer should read input values in source tuples. | |
Static Public Member Functions | |
static AggComputer * | newAggComputer (AggFunction aggFunction, TupleAttributeDescriptor const *pAttrDesc) |
Virtual constructor. | |
Protected Attributes | |
int | iInputAttr |
Private Member Functions | |
T & | interpretDatum (TupleDatum &datum) |
T const & | interpretDatum (TupleDatum const &datum) |
Private Attributes | |
bool | isResultNull |
True until a non-null input value is seen. |
Definition at line 180 of file AggComputerImpl.h.
T& SumAggComputer< T >::interpretDatum | ( | TupleDatum & | datum | ) | [inline, private] |
Definition at line 187 of file AggComputerImpl.h.
References TupleDatum::cbData, and TupleDatum::pData.
Referenced by SumAggComputer< T >::clearAccumulator(), and SumAggComputer< T >::updateAccumulator().
00188 { 00189 assert(datum.cbData == sizeof(T)); 00190 assert(datum.pData); 00191 return *reinterpret_cast<T *>(const_cast<PBuffer>(datum.pData)); 00192 }
T const& SumAggComputer< T >::interpretDatum | ( | TupleDatum const & | datum | ) | [inline, private] |
Definition at line 194 of file AggComputerImpl.h.
References TupleDatum::cbData, and TupleDatum::pData.
00195 { 00196 assert(datum.cbData == sizeof(T)); 00197 assert(datum.pData); 00198 return *reinterpret_cast<T const *>(datum.pData); 00199 }
virtual void SumAggComputer< T >::clearAccumulator | ( | TupleDatum & | accumulatorDatum | ) | [inline, virtual] |
Clears an accumulator.
accumulatorDatum | in-memory value to be cleared |
Implements AggComputer.
Definition at line 203 of file AggComputerImpl.h.
References SumAggComputer< T >::interpretDatum(), SumAggComputer< T >::isResultNull, and sum().
00204 { 00205 T &sum = interpretDatum(accumulatorDatum); 00206 sum = 0; 00207 00208 isResultNull = true; 00209 }
virtual void SumAggComputer< T >::updateAccumulator | ( | TupleDatum & | accumulatorDatum, | |
TupleData const & | inputTuple | |||
) | [inline, virtual] |
Updates an accumulator with a new input tuple.
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 212 of file AggComputerImpl.h.
References AggComputer::iInputAttr, SumAggComputer< T >::interpretDatum(), SumAggComputer< T >::isResultNull, TupleDatum::pData, and sum().
00215 { 00216 assert(iInputAttr != -1); 00217 TupleDatum const &inputDatum = inputTuple[iInputAttr]; 00218 if (!inputDatum.pData) { 00219 // SQL2003 Part 2 Section 10.9 General Rule 4.a 00220 // TODO jvs 6-Oct-2005: we're supposed to queue a warning 00221 // for null value eliminated in set function 00222 return; 00223 } else { 00224 isResultNull = false; 00225 } 00226 T &sum = interpretDatum(accumulatorDatum); 00227 if (inputDatum.pData) { 00228 T input = interpretDatum(inputDatum); 00229 // TODO jvs 6-Oct-2005: overflow check 00230 sum += input; 00231 } 00232 }
virtual void SumAggComputer< T >::computeOutput | ( | TupleDatum & | outputDatum, | |
TupleDatum const & | accumulatorDatum | |||
) | [inline, virtual] |
Computes an output based on accumulator state.
outputDatum | receives reference to computed output in preparation for marshalling result | |
accumulatorDatum | final in-memory accumulator state |
Implements AggComputer.
Definition at line 235 of file AggComputerImpl.h.
References SumAggComputer< T >::isResultNull, and TupleDatum::pData.
00238 { 00239 // Set output to alias accumulator value directly. 00240 outputDatum = accumulatorDatum; 00241 if (isResultNull) { 00242 outputDatum.pData = NULL; 00243 } 00244 }
virtual void SumAggComputer< T >::initAccumulator | ( | TupleDatum & | accumulatorDatumDest, | |
TupleData const & | inputTuple | |||
) | [inline, virtual] |
Initializes a new accumulator datum from an input tuple.
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 246 of file AggComputerImpl.h.
References AggComputer::iInputAttr, SumAggComputer< T >::isResultNull, and TupleDatum::memCopyFrom().
00249 { 00250 accumulatorDatumDest.memCopyFrom(inputTuple[iInputAttr]); 00251 isResultNull = false; 00252 }
virtual void SumAggComputer< T >::initAccumulator | ( | TupleDatum & | accumulatorDatumSrc, | |
TupleDatum & | accumulatorDatumDest | |||
) | [inline, virtual] |
Initializes a new accumulator datum from an existing accumulator datum.
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 254 of file AggComputerImpl.h.
References SumAggComputer< T >::isResultNull, and TupleDatum::memCopyFrom().
00257 { 00258 accumulatorDatumDest.memCopyFrom(accumulatorDatumSrc); 00259 isResultNull = false; 00260 }
virtual void SumAggComputer< T >::updateAccumulator | ( | TupleDatum & | accumulatorDatumSrc, | |
TupleDatum & | accumulatorDatumDest, | |||
TupleData const & | inputTuple | |||
) | [inline, virtual] |
Computes a new accumulator from an existing accumulator dataum and a new input tuple.
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 262 of file AggComputerImpl.h.
References AggComputer::iInputAttr, SumAggComputer< T >::interpretDatum(), TupleDatum::memCopyFrom(), and TupleDatum::pData.
00266 { 00267 TupleDatum const &inputDatum = inputTuple[iInputAttr]; 00268 00269 if (!accumulatorDatumSrc.pData) { 00270 accumulatorDatumDest.memCopyFrom(inputDatum); 00271 } else { 00272 T sumSrc = interpretDatum(accumulatorDatumSrc); 00273 T &sumDest = interpretDatum(accumulatorDatumDest); 00274 00275 if (inputDatum.pData) { 00276 T sumInput = interpretDatum(inputDatum); 00277 sumDest = sumSrc + sumInput; 00278 } else { 00279 sumDest = sumSrc; 00280 } 00281 } 00282 }
AggComputer * AggComputer::newAggComputer | ( | AggFunction | aggFunction, | |
TupleAttributeDescriptor const * | pAttrDesc | |||
) | [static, inherited] |
Virtual constructor.
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.
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 }
bool SumAggComputer< T >::isResultNull [private] |
True until a non-null input value is seen.
Definition at line 185 of file AggComputerImpl.h.
Referenced by SumAggComputer< T >::clearAccumulator(), SumAggComputer< T >::computeOutput(), SumAggComputer< T >::initAccumulator(), and SumAggComputer< T >::updateAccumulator().
int AggComputer::iInputAttr [protected, inherited] |
Definition at line 50 of file AggComputer.h.
Referenced by AggComputer::AggComputer(), CountStarAggComputer::clearAccumulator(), SumAggComputer< T >::initAccumulator(), ExtremeAggComputer::initAccumulator(), CountNullableAggComputer::initAccumulator(), CountStarAggComputer::initAccumulator(), AggComputer::setInputAttrIndex(), SumAggComputer< T >::updateAccumulator(), ExtremeAggComputer::updateAccumulator(), and CountNullableAggComputer::updateAccumulator().