Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/query_processing/column_computation_algebra_operator.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <query_processing/definitions.hpp>
00004 #include <util/getname.hpp>
00005 
00006 namespace CoGaDB {
00007     namespace query_processing {
00008         namespace physical_operator {
00009 
00010             class CPU_ColumnAlgebraOperator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00011                                 public:
00012                                         typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00013 
00014                                         CPU_ColumnAlgebraOperator(const hype::SchedulingDecision& sched_dec,
00015                                                             TypedOperatorPtr child,
00016                                                             const std::string& column1_name,
00017                                                             const std::string& column2_name,
00018                                                             const std::string& result_col_name, 
00019                                                             ColumnAlgebraOperation operation)
00020                                                                                  : UnaryOperator<TablePtr,TablePtr>(sched_dec, child),
00021                                                                                 column1_name_(column1_name), 
00022                                                                                 column2_name_(column2_name), 
00023                                                                                 result_column_name_(result_col_name),
00024                 operation_(operation) {
00025                                         }
00026 
00027                                         virtual bool execute() {
00028                                             /*
00029                                             if(!this->getInputData()->ColumnAlgebraOperation(column1_name_,column2_name_,result_column_name_,operation_,CoGaDB::CPU)){
00030                                                 return false;
00031                                             }
00032                                             
00033                                             this->result_=this->getInputData();
00034                                             */
00035                                             this->result_=BaseTable::ColumnAlgebraOperation(this->getInputData(),column1_name_,column2_name_,result_column_name_,operation_,CoGaDB::CPU);
00036 
00037                     if (this->result_) {
00038                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00039                                                 return true;
00040                     } else
00041                                                 return false;
00042                                         }
00043 
00044                 virtual ~CPU_ColumnAlgebraOperator() {
00045                 }
00046                                 private:
00047                                         std::string column1_name_;
00048                                         std::string column2_name_;
00049                                         std::string result_column_name_;
00050                                         CoGaDB::ColumnAlgebraOperation operation_;
00051                         };
00052 
00053             class GPU_ColumnAlgebraOperator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00054                                 public:
00055                                         typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00056 
00057                                         GPU_ColumnAlgebraOperator(const hype::SchedulingDecision& sched_dec,
00058                                                             TypedOperatorPtr child,
00059                                                             const std::string& column1_name,
00060                                                             const std::string& column2_name,
00061                                                             const std::string& result_col_name, 
00062                                                             ColumnAlgebraOperation operation) : UnaryOperator<TablePtr,TablePtr>(sched_dec, child),
00063                                                             column1_name_(column1_name), 
00064                                                             column2_name_(column2_name), 
00065                                                             result_column_name_(result_col_name),
00066                                                             operation_(operation) {
00067                                         }
00068 
00069                                         virtual bool execute() {
00070                                             
00071                                             this->result_=BaseTable::ColumnAlgebraOperation(this->getInputData(),column1_name_,column2_name_,result_column_name_,operation_,CoGaDB::GPU);
00072 
00073                     if (this->result_) {
00074                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00075                                                 return true;
00076                     } else
00077                                                 return false;
00078                                         }
00079 
00080                 virtual ~GPU_ColumnAlgebraOperator() {
00081                 }
00082                                 private:
00083                                         std::string column1_name_;
00084                                         std::string column2_name_;
00085                                         std::string result_column_name_;
00086                                         CoGaDB::ColumnAlgebraOperation operation_;
00087                         };
00088 
00089                         Physical_Operator_Map_Ptr map_init_function_column_algebra_operator();
00090                         TypedOperatorPtr create_CPU_ColumnAlgebra_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00091                         TypedOperatorPtr create_GPU_ColumnAlgebra_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00092 
00093                 }//end namespace physical_operator
00094 
00095                 //extern Map_Init_Function init_function_sort_operator;
00096 
00097                 //Map_Init_Function init_function_sort_operator=physical_operator::map_init_function_column_algebra_operator; //boost::bind();
00098 
00099         namespace logical_operator {
00100 
00101                         class Logical_ColumnAlgebraOperator : public hype::queryprocessing::TypedNode_Impl<TablePtr,physical_operator::map_init_function_column_algebra_operator> //init_function_sort_operator>
00102                         {
00103                                 public:
00104 
00105                                         Logical_ColumnAlgebraOperator(const std::string& column1_name,
00106                                                      const std::string& column2_name,
00107                                                      const std::string& result_col_name, 
00108                                                      ColumnAlgebraOperation operation,
00109                                                      hype::DeviceConstraint dev_constr = CoGaDB::RuntimeConfiguration::instance().getGlobalDeviceConstraint())
00110                                                                  : TypedNode_Impl<TablePtr,physical_operator::map_init_function_column_algebra_operator>(false,dev_constr), 
00111                                                                         column1_name_(column1_name), 
00112                                                                         column2_name_(column2_name), 
00113                                                                         result_column_name_(result_col_name),
00114                 operation_(operation) {
00115                                         }
00116 
00117                                         virtual unsigned int getOutputResultSize() const {
00118                                                 return 10;
00119                                         }
00120 
00121                 virtual double getCalculatedSelectivity() const {
00122                                                 return 0.1;
00123                                         }
00124 
00125                                         virtual std::string getOperationName() const {
00126                                                 return "ColumnAlgebraOperator";
00127                                         }
00128                                         std::string toString(bool verbose) const{
00129                                             std::string result="ColumnAlgebraOperator";
00130                                             if(verbose){
00131                                                 result+=" (";
00132                                                 result+=result_column_name_;
00133                                                 result+="=";                                                
00134                                                 result+=util::getName(operation_);
00135                                                 result+="(";
00136                                                 result+=column1_name_;
00137                                                 result+=",";
00138                                                 result+=column2_name_;
00139                                                 result+=")";
00140 
00141                                                 result+=")";
00142                                             }
00143                                             return result;
00144 
00145                                         }
00146                                         const std::string& getColumn1Name() {
00147                                                 return column1_name_;
00148                                         }
00149 
00150                                         const std::string& getColumn2Name() {
00151                                                 return column2_name_;
00152                                         }
00153 
00154                                         const std::string& getResultColumnName() {
00155                                                 return result_column_name_;
00156                                         }                                        
00157 
00158                                         CoGaDB::ColumnAlgebraOperation getColumnAlgebraOperation(){
00159                                                 return operation_;
00160                                         }    
00161                         private:
00162                                         std::string column1_name_;
00163                                         std::string column2_name_;
00164                                         std::string result_column_name_;
00165                                         CoGaDB::ColumnAlgebraOperation operation_;
00166                         };
00167 
00168                 }//end namespace logical_operator
00169 
00170         }//end namespace query_processing
00171 
00172 }; //end namespace CogaDB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines