#include <AggComputerImpl.h>
Inheritance diagram for ExtremeAggComputer:
Public Member Functions | |
ExtremeAggComputer (AggFunction aggFunctionInit, TupleAttributeDescriptor const &attrDesc) | |
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 | |
void | copyInputToAccumulator (TupleDatum &accumulatorDatum, TupleDatum const &inputDatum) |
Private Attributes | |
StoredTypeDescriptor const * | pTypeDescriptor |
Type descriptor used as comparison functor. | |
AggFunction | aggFunction |
Agg function implemented by this agg computer. | |
bool | isResultNull |
True until a non-null input value is seen. |
Definition at line 120 of file AggComputerImpl.h.
ExtremeAggComputer::ExtremeAggComputer | ( | AggFunction | aggFunctionInit, | |
TupleAttributeDescriptor const & | attrDesc | |||
) | [explicit] |
Definition at line 222 of file AggComputer.cpp.
References aggFunction, TupleAttributeDescriptor::pTypeDescriptor, and pTypeDescriptor.
00225 { 00226 aggFunction = aggFunctionInit; 00227 pTypeDescriptor = attrDesc.pTypeDescriptor; 00228 }
void ExtremeAggComputer::copyInputToAccumulator | ( | TupleDatum & | accumulatorDatum, | |
TupleDatum const & | inputDatum | |||
) | [inline, private] |
Definition at line 235 of file AggComputer.cpp.
References TupleDatum::memCopyFrom().
Referenced by updateAccumulator().
00238 { 00239 // Use the utility function to copy from inputDatum's buffer to 00240 // accumulatorDatum. 00241 accumulatorDatum.memCopyFrom(inputDatum); 00242 }
void ExtremeAggComputer::clearAccumulator | ( | TupleDatum & | accumulatorDatum | ) | [virtual] |
Clears an accumulator.
accumulatorDatum | in-memory value to be cleared |
Implements AggComputer.
Definition at line 230 of file AggComputer.cpp.
References isResultNull.
00231 { 00232 isResultNull = true; 00233 }
void ExtremeAggComputer::updateAccumulator | ( | TupleDatum & | accumulatorDatum, | |
TupleData const & | inputTuple | |||
) | [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 244 of file AggComputer.cpp.
References AGG_FUNC_MIN, AGG_FUNC_SINGLE_VALUE, aggFunction, TupleDatum::cbData, StoredTypeDescriptor::compareValues(), copyInputToAccumulator(), AggComputer::iInputAttr, isResultNull, TupleDatum::pData, and pTypeDescriptor.
00247 { 00248 assert(iInputAttr != -1); 00249 TupleDatum const &inputDatum = inputTuple[iInputAttr]; 00250 if (!inputDatum.pData) { 00251 // SQL2003 Part 2 Section 10.9 General Rule 4.a 00252 // TODO jvs 6-Oct-2005: we're supposed to queue a warning 00253 // for null value eliminated in set function 00254 return; 00255 } 00256 if (isResultNull) { 00257 isResultNull = false; 00258 // first non-null input: use it 00259 copyInputToAccumulator(accumulatorDatum, inputDatum); 00260 return; 00261 } else if (aggFunction == AGG_FUNC_SINGLE_VALUE) { 00262 throw FennelExcn( 00263 FennelResource::instance().scalarQueryReturnedMultipleRows()); 00264 } 00265 00266 // c = (input - accumulator) 00267 int c = pTypeDescriptor->compareValues( 00268 inputDatum.pData, 00269 inputDatum.cbData, 00270 accumulatorDatum.pData, 00271 accumulatorDatum.cbData); 00272 if (aggFunction == AGG_FUNC_MIN) { 00273 // invert comparison for MIN 00274 c = -c; 00275 } 00276 if (c <= 0) { 00277 // for MAX, input has to be greater than accumulator for accumulator 00278 // to be updated 00279 return; 00280 } 00281 copyInputToAccumulator(accumulatorDatum, inputDatum); 00282 }
void ExtremeAggComputer::computeOutput | ( | TupleDatum & | outputDatum, | |
TupleDatum const & | accumulatorDatum | |||
) | [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 284 of file AggComputer.cpp.
References isResultNull, and TupleDatum::pData.
00287 { 00288 // Set output to alias accumulator value directly. 00289 outputDatum = accumulatorDatum; 00290 if (isResultNull) { 00291 outputDatum.pData = NULL; 00292 } 00293 }
void ExtremeAggComputer::initAccumulator | ( | TupleDatum & | accumulatorDatumDest, | |
TupleData const & | inputTuple | |||
) | [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 295 of file AggComputer.cpp.
References AggComputer::iInputAttr, isResultNull, and TupleDatum::memCopyFrom().
00298 { 00299 accumulatorDatumDest.memCopyFrom(inputTuple[iInputAttr]); 00300 isResultNull = false; 00301 }
void ExtremeAggComputer::initAccumulator | ( | TupleDatum & | accumulatorDatumSrc, | |
TupleDatum & | accumulatorDatumDest | |||
) | [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 303 of file AggComputer.cpp.
References isResultNull, and TupleDatum::memCopyFrom().
00306 { 00307 accumulatorDatumDest.memCopyFrom(accumulatorDatumSrc); 00308 isResultNull = false; 00309 }
void ExtremeAggComputer::updateAccumulator | ( | TupleDatum & | accumulatorDatumSrc, | |
TupleDatum & | accumulatorDatumDest, | |||
TupleData const & | inputTuple | |||
) | [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 311 of file AggComputer.cpp.
References AGG_FUNC_MIN, AGG_FUNC_SINGLE_VALUE, aggFunction, TupleDatum::cbData, StoredTypeDescriptor::compareValues(), AggComputer::iInputAttr, TupleDatum::memCopyFrom(), TupleDatum::pData, and pTypeDescriptor.
00315 { 00316 if (aggFunction == AGG_FUNC_SINGLE_VALUE) { 00317 throw FennelExcn( 00318 FennelResource::instance().scalarQueryReturnedMultipleRows()); 00319 } 00320 00321 TupleDatum const &inputDatum = inputTuple[iInputAttr]; 00322 00323 if (!accumulatorDatumSrc.pData) { 00324 accumulatorDatumDest.memCopyFrom(inputDatum); 00325 } else if (inputDatum.pData) { 00326 // c = (input - accumulator) 00327 int c = pTypeDescriptor->compareValues( 00328 inputDatum.pData, 00329 inputDatum.cbData, 00330 accumulatorDatumSrc.pData, 00331 accumulatorDatumSrc.cbData); 00332 if (aggFunction == AGG_FUNC_MIN) { 00333 // invert comparison for MIN 00334 c = -c; 00335 } 00336 if (c <= 0) { 00337 // for MAX, input has to be greater than accumulator for accumulator 00338 // to be updated 00339 accumulatorDatumDest.memCopyFrom(accumulatorDatumSrc); 00340 } else { 00341 accumulatorDatumDest.memCopyFrom(inputDatum); 00342 } 00343 } else { 00344 accumulatorDatumDest.memCopyFrom(accumulatorDatumSrc); 00345 } 00346 }
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 }
StoredTypeDescriptor const* ExtremeAggComputer::pTypeDescriptor [private] |
Type descriptor used as comparison functor.
Definition at line 126 of file AggComputerImpl.h.
Referenced by ExtremeAggComputer(), and updateAccumulator().
AggFunction ExtremeAggComputer::aggFunction [private] |
Agg function implemented by this agg computer.
Definition at line 131 of file AggComputerImpl.h.
Referenced by ExtremeAggComputer(), and updateAccumulator().
bool ExtremeAggComputer::isResultNull [private] |
True until a non-null input value is seen.
Definition at line 136 of file AggComputerImpl.h.
Referenced by clearAccumulator(), computeOutput(), initAccumulator(), and updateAccumulator().
int AggComputer::iInputAttr [protected, inherited] |
Definition at line 50 of file AggComputer.h.
Referenced by AggComputer::AggComputer(), CountStarAggComputer::clearAccumulator(), SumAggComputer< T >::initAccumulator(), initAccumulator(), CountNullableAggComputer::initAccumulator(), CountStarAggComputer::initAccumulator(), AggComputer::setInputAttrIndex(), SumAggComputer< T >::updateAccumulator(), updateAccumulator(), and CountNullableAggComputer::updateAccumulator().