LbmSortedAggExecStream.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmSortedAggExecStream.cpp#6 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 LucidEra, Inc.
00005 // Copyright (C) 2005-2009 The Eigenbase Project
00006 //
00007 // This program is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by the Free
00009 // Software Foundation; either version 2 of the License, or (at your option)
00010 // any later version approved by The Eigenbase Project.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 #include "fennel/common/CommonPreamble.h"
00023 #include "fennel/lucidera/bitmap/LbmSortedAggExecStream.h"
00024 #include "fennel/exec/ExecStreamBufAccessor.h"
00025 #include "fennel/lucidera/bitmap/LbmByteSegment.h"
00026 #include "fennel/tuple/StandardTypeDescriptor.h"
00027 
00028 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSortedAggExecStream.cpp#6 $");
00029 
00037 class LbmRepeatingAggComputer : public AggComputer
00038 {
00039     AggComputer *pComputer;
00040 
00041 public:
00042     explicit LbmRepeatingAggComputer(AggComputer *pComputer);
00043 
00044     // implement AggComputer
00045     virtual void setInputAttrIndex(uint iInputAttrIndex);
00046 
00047     virtual void clearAccumulator(
00048         TupleDatum &accumulatorDatum);
00049 
00050     virtual void updateAccumulator(
00051         TupleDatum &accumulatorDatum,
00052         TupleData const &inputTuple);
00053 
00054     virtual void computeOutput(
00055         TupleDatum &outputDatum,
00056         TupleDatum const &accumulatorDatum);
00057 
00058     // unused...
00059     virtual void initAccumulator(
00060         TupleDatum &accumulatorDatumDest,
00061         TupleData const &inputTuple);
00062 
00063     virtual void initAccumulator(
00064         TupleDatum &accumulatorDatumSrc,
00065         TupleDatum &accumulatorDatumDest);
00066 
00067     virtual void updateAccumulator(
00068         TupleDatum &accumulatorDatumSrc,
00069         TupleDatum &accumulatorDatumDest,
00070         TupleData const &inputTuple);
00071 };
00072 
00073 LbmRepeatingAggComputer::LbmRepeatingAggComputer(
00074     AggComputer *pComputer)
00075 {
00076     this->pComputer = pComputer;
00077 }
00078 
00079 void LbmRepeatingAggComputer::setInputAttrIndex(uint iInputAttrIndex)
00080 {
00081     AggComputer::setInputAttrIndex(iInputAttrIndex);
00082     pComputer->setInputAttrIndex(iInputAttrIndex);
00083 }
00084 
00085 void LbmRepeatingAggComputer::clearAccumulator(
00086     TupleDatum &accumulatorDatum)
00087 {
00088     pComputer->clearAccumulator(accumulatorDatum);
00089 }
00090 
00091 void LbmRepeatingAggComputer::updateAccumulator(
00092     TupleDatum &accumulatorDatum,
00093     TupleData const &inputTuple)
00094 {
00095     // segment data should be contained in the last field
00096     TupleDatum segmentDatum = inputTuple[inputTuple.size() - 1];
00097     uint loops = LbmByteSegment::countBits(segmentDatum);
00098 
00099     for (uint i = 0; i < loops; i++) {
00100         pComputer->updateAccumulator(accumulatorDatum, inputTuple);
00101     }
00102 }
00103 
00104 void LbmRepeatingAggComputer::computeOutput(
00105     TupleDatum &outputDatum,
00106     TupleDatum const &accumulatorDatum)
00107 {
00108     pComputer->computeOutput(outputDatum, accumulatorDatum);
00109 }
00110 
00111 void LbmRepeatingAggComputer::initAccumulator(
00112     TupleDatum &accumulatorDatumDest,
00113     TupleData const &inputTuple)
00114 {
00115     // sorted aggregates never use this call
00116     assert(false);
00117 }
00118 
00119 void LbmRepeatingAggComputer::initAccumulator(
00120     TupleDatum &accumulatorDatumSrc,
00121     TupleDatum &accumulatorDatumDest)
00122 {
00123     // sorted aggregates never use this call
00124     assert(false);
00125 }
00126 
00127 void LbmRepeatingAggComputer::updateAccumulator(
00128     TupleDatum &accumulatorDatumSrc,
00129     TupleDatum &accumulatorDatumDest,
00130     TupleData const &inputTuple)
00131 {
00132     // sorted aggregates never use this call
00133     assert(false);
00134 }
00135 
00136 void LbmSortedAggExecStream::prepare(
00137     LbmSortedAggExecStreamParams const &params)
00138 {
00139     SortedAggExecStream::prepare(params);
00140 }
00141 
00142 AggComputer *LbmSortedAggExecStream::newAggComputer(
00143     AggFunction aggFunction,
00144     TupleAttributeDescriptor const *pAttrDesc)
00145 {
00146     AggComputer *pComputer =
00147         SortedAggExecStream::newAggComputer(aggFunction, pAttrDesc);
00148 
00149     switch (aggFunction) {
00150     case AGG_FUNC_COUNT:
00151     case AGG_FUNC_SUM:
00152         pComputer = new LbmRepeatingAggComputer(pComputer);
00153     default:
00154         ;
00155     }
00156     return pComputer;
00157 }
00158 
00159 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSortedAggExecStream.cpp#6 $");
00160 
00161 // End LbmSortedAggExecStream.cpp

Generated on Mon Jun 22 04:00:19 2009 for Fennel by  doxygen 1.5.1