Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/core/base_table.hpp
Go to the documentation of this file.
00001 
00002 #pragma once
00003 #include <core/global_definitions.hpp>
00004 #include <core/base_column.hpp>
00005 #include <core/selection_expression.hpp>
00006 
00007 namespace CoGaDB{
00008 
00009 class LookupColumn;
00010 
00011 class BaseTable{
00012         friend class LookupColumn;
00013         public:
00014         typedef shared_pointer_namespace::shared_ptr<BaseTable> TablePtr;
00015         /***************** constructors and destructor *****************/
00016         BaseTable(const std::string& name, const TableSchema& schema);
00017 
00018         //BaseTable(const std::string& name, const std::vector<ColumnPtr>& columns); //if we already have columns, we can use this constructor to pass them in the BaseTable without any copy effort
00019         virtual ~BaseTable();
00020         /***************** utility functions *****************/
00021         const std::string& getName() const throw();
00022 
00023         const TableSchema getSchema() const throw();
00024 
00025         virtual void print() = 0;
00027         virtual bool store() = 0;
00029         virtual bool load() = 0;
00030         virtual bool loadDatafromFile(std::string filepath) = 0;
00031 
00032         virtual const TablePtr materialize() const = 0;
00033         
00034         virtual bool addColumn(ColumnPtr) = 0;
00035         
00036         static const TablePtr createResultTable(TablePtr table, PositionListPtr tids, MaterializationStatus mat_stat, const std::string& operation_name);
00037 
00038         /***************** status report *****************/
00039         virtual unsigned int getNumberofRows() const throw();
00040         //virtual const unsigned int getSizeinBytes() const throw() =0;
00041 
00042         unsigned int getSizeinBytes() const throw(){
00043                 const std::vector<ColumnPtr>& columns = this->getColumns();
00044                 unsigned int size_in_bytes=0;
00045                 std::vector<ColumnPtr>::const_iterator cit;
00046                 for(cit=columns.begin();cit!=columns.end();++cit){
00047                         size_in_bytes+=(*cit)->getSizeinBytes();
00048                 }
00049                 return size_in_bytes;
00050         }
00051 
00052         void printSchema() const {
00053             TableSchema schema = getSchema();
00054             TableSchema::iterator it;
00055             for (it = schema.begin(); it != schema.end(); ++it) {
00056 
00057                 if (it != schema.begin()) std::cout << ", ";
00058                 std::cout << it->second;
00059 
00060             }
00061             std::cout << std::endl;
00062 
00063         }
00064 
00065         virtual bool isMaterialized() const throw() =0;
00066 
00067         /***************** relational operations *****************/
00068         static const TablePtr selection(TablePtr table, const std::string& column_name, const boost::any& value_for_comparison, const ValueComparator& comp, MaterializationStatus mat_stat=MATERIALIZE, ParallelizationMode comp_mode=SERIAL, const ComputeDevice comp_dev=CPU);
00069 
00070         static const TablePtr selection(TablePtr table, const KNF_Selection_Expression&, MaterializationStatus mat_stat=MATERIALIZE, ParallelizationMode comp_mode=SERIAL);
00071 
00072         static const TablePtr selection(TablePtr table, const Disjunction& disjunction, MaterializationStatus mat_stat=MATERIALIZE, ParallelizationMode comp_mode=SERIAL);
00073         
00074         static const TablePtr projection(TablePtr table, const std::list<std::string>& columns_to_select, MaterializationStatus mat_stat=MATERIALIZE, const ComputeDevice comp_dev=CPU);
00075 
00076         static const TablePtr join(TablePtr table1, const std::string& join_column_table1, TablePtr table2, const std::string& join_column_table2, 
00077                                                                                          JoinAlgorithm join_alg=SORT_MERGE_JOIN, MaterializationStatus mat_stat=MATERIALIZE, const ComputeDevice comp_dev=CPU);
00078         
00079         static const TablePtr crossjoin(TablePtr table1, TablePtr table2, MaterializationStatus mat_stat=MATERIALIZE);       
00080         
00081 
00082         //crossjoin(this->getInputDataLeftChild(), this->getInputDataRightChild(), mat_stat_);
00083         
00084         static const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00085         //assumes stable sort!
00086         static const TablePtr sort(TablePtr table, const std::list<std::string>& column_names, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00087         
00088         static const TablePtr groupby(TablePtr table, const std::string& grouping_column, const std::string& aggregation_column, const std::string& result_column_name, AggregationMethod agg_meth=SUM, ComputeDevice comp_dev=CPU);
00089         
00090         static const TablePtr groupby(TablePtr table, const std::list<std::string>& grouping_columns, std::list<std::pair<std::string,AggregationMethod> > aggregation_functions, ComputeDevice comp_dev=CPU);        
00091         /***************** Aggregation Functions *****************/
00093         static TablePtr ColumnConstantOperation(TablePtr tab, const std::string& col_name, const boost::any& value, const std::string& result_col_name, ColumnAlgebraOperation operation, const ComputeDevice comp_dev = CPU);
00095         static TablePtr ColumnAlgebraOperation(TablePtr tab, const std::string& col1_name, const std::string& col2_name, const std::string& result_col_name, ColumnAlgebraOperation operation, const ComputeDevice comp_dev  = CPU);
00097         static TablePtr AddConstantValueColumnOperation(TablePtr tab, const std::string& col_name, AttributeType type, const boost::any& value, const ComputeDevice comp_dev  = CPU);
00098                
00099         
00100         
00101         /***************** read and write operations at BaseTable level *****************/
00102         virtual const Tuple fetchTuple(const TID& id) const = 0;
00103 
00104         virtual bool insert(const Tuple& t) = 0;
00105 
00106         virtual bool update(const std::string& attribute_name, const boost::any& value) = 0;
00107 
00108         virtual bool remove(const std::string& attribute_name, const boost::any& value) = 0;
00109 
00110         virtual const ColumnPtr getColumnbyName(const std::string& column_name) const throw() = 0;
00111         
00112         protected:
00113         virtual const std::vector<ColumnPtr>& getColumns() const = 0;
00114         //const TablePtr groupby(const std::string& grouping_column, const std::string& aggregation_column,  AggregationMethod agg_meth=SUM, ComputeDevice comp_dev=CPU) const;
00115 
00116         // std::vector<ColumnPtr> columns_;
00117         std::string name_;
00118         TableSchema schema_;
00119 };
00120 
00121 typedef BaseTable::TablePtr TablePtr;
00122 
00123 
00124 }; //end namespace CogaDB
00125 
00126 
00127 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines