WinAggHistogramStrA.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/calculator/WinAggHistogramStrA.h#3 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2006-2009 The Eigenbase Project
00005 // Copyright (C) 2006-2009 SQLstream, Inc.
00006 // Copyright (C) 2009-2009 LucidEra, Inc.
00007 //
00008 // This program is free software; you can redistribute it and/or modify it
00009 // under the terms of the GNU General Public License as published by the Free
00010 // Software Foundation; either version 2 of the License, or (at your option)
00011 // any later version approved by The Eigenbase Project.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 //
00022 // WinAggHistogram - Windowed Aggregation Histogram object.
00023 */
00024 
00025 #ifndef Fennel_WinAggHistogramStrA_Included
00026 #define Fennel_WinAggHistogramStrA_Included
00027 
00028 #include "fennel/tuple/TupleDescriptor.h"
00029 #include "fennel/calculator/CalcCommon.h"
00030 #include "fennel/calculator/SqlString.h"
00031 #include "fennel/common/TraceSource.h"
00032 
00033 #include <utility>
00034 #include <set>
00035 
00036 FENNEL_BEGIN_NAMESPACE
00037 
00054 struct StringDesc : public TupleDatum
00055 {
00056     TupleStorageByteLength cbStorage;
00057     StandardTypeDescriptorOrdinal mType;
00058 
00059     StringDesc() {}
00060     ~StringDesc() {}
00061 
00062     StringDesc(StringDesc const &other)
00063     {
00064         copyFrom(other);
00065     }
00066 
00067     StringDesc& operator = (StringDesc const &other)
00068     {
00069         copyFrom(other);
00070         return *this;
00071     }
00072 
00073 
00074     void copyFrom(StringDesc const &other)
00075     {
00076         TupleDatum::copyFrom(other);
00077         cbStorage = other.cbStorage;
00078         mType = other.mType;
00079     }
00080 
00081     char* pointer() const;
00082     TupleStorageByteLength stringLength() const;
00083 
00084 };
00085 
00086 class FENNEL_CALCULATOR_EXPORT WinAggHistogramStrA
00087 {
00088 public:
00089     WinAggHistogramStrA()
00090         : currentWindow(),
00091           nullRows(0),
00092           queue()
00093     {}
00094 
00095     ~WinAggHistogramStrA()
00096     {}
00097 
00098     typedef struct _StringDescCompare
00099     {
00100         bool operator () (const StringDesc& str1, const StringDesc& str2) const
00101         {
00102             if (!str1.isNull() && !str2.isNull()) {
00103                 int32_t result = SqlStrCmp<1,1>(
00104                     str1.pointer(), str1.stringLength(),
00105                     str2.pointer(), str2.stringLength());
00106                 return result < 0;
00107             } else {
00108                 return str2.isNull();
00109             }
00110         }
00111     } StringDescCompare;
00112 
00113     typedef multiset<StringDesc,StringDescCompare> WinAggData;
00114 
00115     typedef deque<StringDesc> WinAggQueue;
00116 
00121     //
00122     void addRow(RegisterRef<char*>* node);
00123 
00128     //
00129     void dropRow(RegisterRef<char*>* node);
00130 
00134     void getMin(RegisterRef<char*>* node);
00135 
00139     void getMax(RegisterRef<char*>* node);
00140 
00144     void getFirstValue(RegisterRef<char*>* node);
00145 
00149     void getLastValue(RegisterRef<char*>* node);
00150 
00151 protected:
00152     void setReturnReg(RegisterRef<char*>* dest, const StringDesc& src);
00153 
00154 private:
00155     WinAggData currentWindow;   // Holds the values currently in the window.
00156     int64_t nullRows;           // Couunt of null entries
00157 
00159     WinAggQueue queue;
00160 };
00161 
00162 FENNEL_END_NAMESPACE
00163 
00164 #endif
00165 
00166 // End WinAggHistogramStrA.h

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