Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/compression/tmp/db2/core/lookup_array.hpp
Go to the documentation of this file.
00001 
00002 #pragma once
00003 
00004 #include <core/column_base_typed.hpp>
00005 #include <core/column.hpp>
00006 #include <lookup_table/lookup_column.hpp>
00007 #include <core/base_table.hpp>
00008 
00009 namespace CoGaDB{
00010 
00023 template<class T>
00024 class LookupArray : public ColumnBaseTyped<T>{
00025         public:
00026         /***************** constructors and destructor *****************/
00027         LookupArray(const std::string& name, AttributeType db_type, ColumnPtr column, PositionListPtr tids);
00028         virtual ~LookupArray();
00029 
00030         virtual bool insert(const boost::any& new_Value);
00031         virtual bool insert(const T& new_Value);
00032         virtual bool update(TID tid, const boost::any& new_value);
00033         virtual bool update(PositionListPtr tid, const boost::any& new_value);  
00034         
00035         virtual bool remove(TID tid);
00036         //assumes tid list is sorted ascending
00037         virtual bool remove(PositionListPtr tid);
00038         virtual bool clearContent();
00039 
00040         virtual const boost::any get(TID tid);
00041         //virtual const boost::any* const getRawData()=0;
00042         virtual void print() const throw();
00043         virtual size_t size() const throw();
00044         virtual unsigned int getSizeinBytes() const throw();
00045 
00046         virtual const ColumnPtr copy() const;
00047 
00048         virtual bool store(const std::string& path);
00049         virtual bool load(const std::string& path);
00050         virtual bool isMaterialized() const  throw();
00051         virtual bool isCompressed() const  throw();             
00053         virtual T& operator[](const int index);
00054         private:
00055         shared_pointer_namespace::shared_ptr<ColumnBaseTyped<T> > column_;
00056         PositionListPtr tids_;
00057 };
00058 
00059         //typedef shared_pointer_namespace::shared_ptr<LookupArray> LookupArrayPtr;
00060 
00061 /***************** Start of Implementation Section ******************/
00062 
00063         
00064         template<class T>
00065         LookupArray<T>::LookupArray(const std::string& name, AttributeType db_type, ColumnPtr column, PositionListPtr tids) 
00066                                                 : ColumnBaseTyped<T>(name, db_type),
00067                                                   column_( shared_pointer_namespace::static_pointer_cast<ColumnBaseTyped<T> > (column) ),
00068                                                   tids_(tids) {
00069         
00070                 assert(column_!=NULL);
00071                 assert(tids_!=NULL);
00072                 assert(db_type==column->getType());
00073 
00074         }
00075 
00076         template<class T>
00077         LookupArray<T>::~LookupArray(){
00078 
00079         }
00080 
00081         template<class T>
00082         bool LookupArray<T>::insert(const boost::any& ){
00083                 return false;
00084         }
00085         template<class T>
00086         bool LookupArray<T>::insert(const T&){
00087                 return false;
00088         }
00089         template<class T>
00090         bool LookupArray<T>::update(TID , const boost::any& ){
00091                 return  false;
00092         }
00093 
00094         template<class T>
00095         bool LookupArray<T>::update(PositionListPtr, const boost::any&){
00096                 return  false;                  
00097         }
00098         
00099         template<class T>
00100         bool LookupArray<T>::remove(TID ){
00101 
00102                 return false;
00103         }
00104         
00105         //assumes tid list is sorted ascending
00106         template<class T>
00107         bool LookupArray<T>::remove(PositionListPtr){
00108                 return false;
00109         }
00110 
00111         template<class T>
00112         bool LookupArray<T>::clearContent(){
00113                 return false;
00114         }
00115         
00116         template<class T>
00117         const boost::any LookupArray<T>::get(TID tid){
00118                 return boost::any((*this)[tid]);
00119         }
00120 
00121         template<class T>
00122         void LookupArray<T>::print() const throw(){
00123                 
00124                 const shared_pointer_namespace::shared_ptr<ColumnBaseTyped<T> > column = column_;
00125                 const PositionListPtr tids = tids_;
00126 
00127                 std::cout << "Lookup Array for Column " << column_->getName() << " ";
00128                 if(column_->isMaterialized()){
00129                         std::cout << "which is a materialized Column" << std::endl;
00130                 }else{
00131                         std::cout << "which is a LookupArray of a Lookup column" << std::endl;
00132                 }
00133                 std::cout << "| values | Translatetion TIDS | Index in Lookup Table |" << std::endl;
00134                 for(unsigned int i=0;i<tids->size();i++){
00135                         std::cout << "| " << (*column_)[(*tids_)[i]] << " | " << (*tids_)[i] << " | " << i << " |" << std::endl;
00136                 }
00137 
00138 
00139         }
00140         template<class T>
00141         size_t LookupArray<T>::size() const throw(){
00142 
00143                 return tids_->size();
00144         }
00145         template<class T>
00146         const ColumnPtr LookupArray<T>::copy() const{
00147                 PositionListPtr new_tids (new PositionList(*tids_));
00148                 return ColumnPtr(new LookupArray<T>(this->name_,this->db_type_,this->column_,new_tids));
00149         }
00150         /***************** relational operations on LookupArrays which return lookup tables *****************/
00151 //      template<class T>
00152 //      const std::vector<TID> LookupArray<T>::sort(const ComputeDevice comp_dev) const {
00153 
00154 //              return std::vector<TID>();
00155 //      }
00156 
00157 //      template<class T> 
00158 //      const std::vector<TID> LookupArray<T>::selection(const boost::any& value_for_comparison, const ValueComparator comp, const ComputeDevice comp_dev) const {
00159 //              return std::vector<TID>();
00160 //      }
00161 //      //join algorithms
00162 //      template<class T>
00163 //      const std::vector<TID_Pair> LookupArray<T>::sort_merge_join(ColumnPtr join_LookupArray, const ComputeDevice comp_dev) const{
00164 //              return std::vector<TID_Pair>();
00165 //      }
00166 //      template<class T>
00167 //      const std::vector<TID_Pair> LookupArray<T>::nested_loop_join(ColumnPtr join_LookupArray, const ComputeDevice comp_dev) const{
00168 //              return false;
00169 //      }
00170         template<class T>
00171         bool LookupArray<T>::store(const std::string&){
00172                 return false;
00173         }
00174         template<class T>
00175         bool LookupArray<T>::load(const std::string&){
00176                 return false;
00177         }
00178         template<class T>
00179         bool LookupArray<T>::isMaterialized() const  throw(){
00180                 return false;
00181         }
00182         template<class T>
00183         bool LookupArray<T>::isCompressed() const  throw(){
00184                 return false;
00185         }
00186         template<class T>
00187         T& LookupArray<T>::operator[](const int index){
00188                 return (*column_)[(*tids_)[index]];
00189         }
00190 
00191         template<class T>
00192         unsigned int LookupArray<T>::getSizeinBytes() const throw(){
00193                 return tids_->capacity()*sizeof(typename PositionList::value_type);
00194         }
00195 
00196 /***************** End of Implementation Section ******************/
00197 
00198 
00199 
00200 }; //end namespace CogaDB
00201 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines