00001 /* 00002 // $Id: //open/dev/fennel/lucidera/colstore/LcsClusterAppendExecStream.h#12 $ 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 #ifndef Fennel_LcsClusterAppendExecStream_Included 00023 #define Fennel_LcsClusterAppendExecStream_Included 00024 00025 #include "fennel/exec/ConduitExecStream.h" 00026 #include "fennel/tuple/TupleData.h" 00027 #include "fennel/tuple/TupleDescriptor.h" 00028 #include "fennel/tuple/TupleAccessor.h" 00029 #include "fennel/ftrs/BTreeExecStream.h" 00030 #include "fennel/lucidera/colstore/LcsClusterNodeWriter.h" 00031 #include "fennel/lucidera/colstore/LcsHash.h" 00032 #include "fennel/lucidera/colstore/LcsClusterDump.h" 00033 #include <boost/scoped_array.hpp> 00034 00035 FENNEL_BEGIN_NAMESPACE 00036 00037 struct LcsClusterAppendExecStreamParams : 00038 public BTreeExecStreamParams, public ConduitExecStreamParams 00039 { 00043 TupleProjection inputProj; 00044 }; 00045 00050 class FENNEL_LCS_EXPORT LcsClusterAppendExecStream : 00051 public BTreeExecStream, public ConduitExecStream 00052 { 00053 protected: 00054 00058 uint blockSize; 00059 00064 TupleDescriptor tableColsTupleDesc; 00065 00069 TupleData clusterColsTupleData; 00070 00074 TupleDescriptor clusterColsTupleDesc; 00075 00079 boost::scoped_array<TupleDescriptor> colTupleDesc; 00080 00084 SegmentAccessor scratchAccessor; 00085 00089 ClusterPageLock bufferLock; 00090 00094 bool overwrite; 00095 00099 bool isDone; 00100 00104 TupleData outputTuple; 00105 00110 TupleAccessor* outputTupleAccessor; 00111 00115 boost::scoped_array<FixedBuffer> outputTupleBuffer; 00116 00120 bool compressCalled; 00121 00125 boost::scoped_array<LcsHash> hash; 00126 00130 uint numColumns; 00131 00135 boost::scoped_array<PBuffer> rowBlock; 00136 00140 uint nRowsMax; 00141 00145 boost::scoped_array<PBuffer> hashBlock; 00146 00150 boost::scoped_array<PBuffer> builderBlock; 00151 00155 uint rowCnt; 00156 00160 bool indexBlockDirty; 00161 00165 LcsRid firstRow; 00166 00170 LcsRid lastRow; 00171 00172 /* First rowid in current load 00173 */ 00174 LcsRid startRow; 00175 00179 SharedLcsClusterNodeWriter lcsBlockBuilder; 00180 00184 boost::scoped_array<LcsHashValOrd> hashValOrd; 00185 00189 boost::scoped_array<boost::scoped_array<FixedBuffer> > tempBuf; 00190 00194 boost::scoped_array<uint> maxValueSize; 00195 00199 bool arraysAlloced; 00200 00204 PLcsClusterNode pIndexBlock; 00205 00209 RecordNum numRowCompressed; 00210 00214 void allocArrays(); 00215 00220 void initLoad(); 00221 00225 void loadExistingBlock(); 00226 00230 void startNewBlock(); 00231 00236 void convertTuplesToCols(); 00237 00241 void addValueOrdinal(uint column, uint16_t vOrd); 00242 00246 bool isRowArrayFull(); 00247 00254 void writeBatch(bool lastBatch); 00255 00260 void writeBlock(); 00261 00270 bool getLastBlock(PLcsClusterNode &pBlock); 00271 00276 void init(); 00277 00286 ExecStreamResult compress(ExecStreamQuantum const &quantum); 00287 00293 virtual void close(); 00294 00301 virtual void initTupleLoadParams(const TupleProjection &inputProj); 00302 00309 virtual ExecStreamResult getTupleForLoad(); 00310 00314 virtual void postProcessTuple(); 00315 00316 public: 00317 virtual void prepare(LcsClusterAppendExecStreamParams const ¶ms); 00318 virtual void open(bool restart); 00319 virtual ExecStreamResult execute(ExecStreamQuantum const &quantum); 00320 virtual void getResourceRequirements( 00321 ExecStreamResourceQuantity &minQuantity, 00322 ExecStreamResourceQuantity &optQuantity); 00323 virtual void closeImpl(); 00324 virtual ExecStreamBufProvision getOutputBufProvision() const; 00325 }; 00326 00327 00328 FENNEL_END_NAMESPACE 00329 00330 #endif 00331 00332 // End LcsClusterAppendExecStream.h