BTreeSearchExecStream.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/ftrs/BTreeSearchExecStream.h#14 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 2004-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_BTreeSearchExecStream_Included
00025 #define Fennel_BTreeSearchExecStream_Included
00026 
00027 #include "fennel/ftrs/BTreeReadExecStream.h"
00028 #include "fennel/exec/ConduitExecStream.h"
00029 #include "fennel/exec/DynamicParam.h"
00030 #include "fennel/common/SearchEndpoint.h"
00031 
00032 FENNEL_BEGIN_NAMESPACE
00033 
00038 struct FENNEL_FTRS_EXPORT BTreeSearchKeyParameter
00039 {
00043     DynamicParamId dynamicParamId;
00044 
00048     uint keyOffset;
00049 
00050     BTreeSearchKeyParameter(
00051         DynamicParamId id,
00052         uint offset) :
00053         dynamicParamId(id),
00054         keyOffset(offset)
00055     {
00056     }
00057 };
00058 
00063 struct FENNEL_FTRS_EXPORT BTreeSearchExecStreamParams
00064     : public BTreeReadExecStreamParams, public ConduitExecStreamParams
00065 {
00069     bool outerJoin;
00070 
00075     TupleProjection inputKeyProj;
00076 
00081     TupleProjection inputJoinProj;
00082 
00088     TupleProjection inputDirectiveProj;
00089 
00094     std::vector<BTreeSearchKeyParameter> searchKeyParams;
00095 };
00096 
00105 class FENNEL_FTRS_EXPORT BTreeSearchExecStream
00106     : public BTreeReadExecStream, public ConduitExecStream
00107 {
00111     enum DirectiveOrdinal {
00112         LOWER_BOUND_DIRECTIVE = 0,
00113         UPPER_BOUND_DIRECTIVE = 1
00114     };
00115 
00116 protected:
00117     TupleProjectionAccessor inputKeyAccessor;
00118     TupleProjectionAccessor inputJoinAccessor;
00119     TupleProjectionAccessor readerKeyAccessor;
00120     TupleProjectionAccessor directiveAccessor;
00121     TupleProjectionAccessor upperBoundAccessor;
00122     TupleDescriptor inputKeyDesc, upperBoundDesc;
00123     TupleData inputKeyData,upperBoundData,readerKeyData,directiveData,
00124         *pSearchKey;
00125     bool outerJoin;
00126     bool preFilterNulls;
00127     uint nJoinAttributes;
00128     SearchEndpoint lowerBoundDirective;
00129     SearchEndpoint upperBoundDirective;
00130     bool leastUpper;
00131     std::vector<BTreeSearchKeyParameter> searchKeyParams;
00132     boost::scoped_array<FixedBuffer> searchKeyBuffer;
00133     bool dynamicKeysRead;
00134     TupleProjection searchKeyProj, upperBoundKeyProj;
00135 
00136     bool innerSearchLoop();
00137     ExecStreamResult innerFetchLoop(
00138         ExecStreamQuantum const &quantum,
00139         uint &nTuples);
00140     void readDirectives();
00141     bool testInterval();
00142 
00146     void readSearchKey();
00147 
00152     void readUpperBoundKey();
00153 
00160     bool checkNextKey();
00161 
00169     virtual bool reachedTupleLimit(uint nTuples);
00170 
00176     bool searchForKey();
00177 
00178 public:
00179     // implement ExecStream
00180     void prepare(BTreeSearchExecStreamParams const &params);
00181     virtual void open(bool restart);
00182     virtual ExecStreamResult execute(ExecStreamQuantum const &quantum);
00183     virtual void closeImpl();
00184 };
00185 
00186 FENNEL_END_NAMESPACE
00187 
00188 #endif
00189 
00190 // End BTreeSearchExecStream.h

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