Column-oriented GPU-accelerated Database Management System
CoGaDB
|
00001 #pragma once 00002 00003 #include <query_processing/definitions.hpp> 00004 #include <util/iostream.hpp> 00005 #include <util/getname.hpp> 00006 #include <sstream> 00007 00008 namespace CoGaDB 00009 { 00010 namespace query_processing 00011 { 00012 namespace physical_operator 00013 { 00014 00015 class CPU_AddConstantValueColumn_Operator : public hype::queryprocessing::UnaryOperator<TablePtr,TablePtr> 00016 { 00017 public: 00018 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr; 00019 CPU_AddConstantValueColumn_Operator(const hype::SchedulingDecision& sched_dec, 00020 TypedOperatorPtr child, 00021 const std::string& col_name, 00022 AttributeType type, 00023 const boost::any& value) 00024 : UnaryOperator<TablePtr,TablePtr>(sched_dec, child), 00025 col_name_(col_name), 00026 type_(type), 00027 value_(value) 00028 { 00029 } 00030 virtual bool execute() { 00031 if(!quiet && verbose && debug) std::cout << "Execute AddConstantValueColumn CPU" << std::endl; 00032 //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU); 00033 //this->result_=BaseTable::sort(this->getInputData(), column_name_,order_, mat_stat_,CPU); 00034 00035 //TablePtr BaseTable::AddConstantValueColumnOperation(TablePtr tab, const std::string& col_name, AttributeType type, const boost::any& value, const ComputeDevice comp_dev) 00036 00037 this->result_=BaseTable::AddConstantValueColumnOperation(this->getInputData(), col_name_, type_, value_, CPU); 00038 if (this->result_) { 00039 setResultSize(((TablePtr) this->result_)->getNumberofRows()); 00040 return true; 00041 } else 00042 return false; 00043 } 00044 virtual ~CPU_AddConstantValueColumn_Operator() {} 00045 private: 00046 std::string col_name_; 00047 AttributeType type_; 00048 boost::any value_; 00049 }; 00050 00051 class GPU_AddConstantValueColumn_Operator : public hype::queryprocessing::UnaryOperator<TablePtr,TablePtr> 00052 { 00053 public: 00054 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr; 00055 GPU_AddConstantValueColumn_Operator(const hype::SchedulingDecision& sched_dec, 00056 TypedOperatorPtr child, 00057 const std::string& col_name, 00058 AttributeType type, 00059 const boost::any& value) 00060 : UnaryOperator<TablePtr,TablePtr>(sched_dec, child), 00061 col_name_(col_name), 00062 type_(type), 00063 value_(value) 00064 { 00065 } 00066 virtual bool execute() { 00067 if(!quiet && verbose && debug) std::cout << "Execute AddConstantValueColumn GPU" << std::endl; 00068 //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU); 00069 this->result_=BaseTable::AddConstantValueColumnOperation(this->getInputData(), col_name_, type_, value_, GPU); 00070 if (this->result_) { 00071 setResultSize(((TablePtr) this->result_)->getNumberofRows()); 00072 return true; 00073 } else 00074 return false; 00075 } 00076 virtual ~GPU_AddConstantValueColumn_Operator() {} 00077 private: 00078 std::string col_name_; 00079 AttributeType type_; 00080 boost::any value_; 00081 }; 00082 00083 Physical_Operator_Map_Ptr map_init_function_addconstantvaluecolumn_operator(); 00084 TypedOperatorPtr create_CPU_AddConstantValueColumn_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child); 00085 TypedOperatorPtr create_GPU_AddConstantValueColumn_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child); 00086 00087 }//end namespace physical_operator 00088 00089 //extern Map_Init_Function init_function_AddConstantValueColumn_operator; 00090 00091 //Map_Init_Function init_function_AddConstantValueColumn_operator=physical_operator::map_init_function_AddConstantValueColumn_operator; //boost::bind(); 00092 00093 namespace logical_operator 00094 { 00095 00096 class Logical_AddConstantValueColumn : public hype::queryprocessing::TypedNode_Impl<TablePtr,physical_operator::map_init_function_addconstantvaluecolumn_operator> //init_function_AddConstantValueColumn_operator> 00097 { 00098 public: 00099 Logical_AddConstantValueColumn(const std::string& col_name, 00100 AttributeType type, 00101 const boost::any& value) 00102 : TypedNode_Impl<TablePtr,physical_operator::map_init_function_addconstantvaluecolumn_operator>(), 00103 col_name_(col_name), 00104 type_(type), 00105 value_(value) 00106 { 00107 } 00108 virtual unsigned int getOutputResultSize() const { 00109 assert(this->left_!=NULL); 00110 return this->left_->getOutputResultSize(); //same #rows as child 00111 } 00112 virtual double getSelectivity() const { 00113 return 1; 00114 } 00115 virtual std::string getOperationName() const { 00116 return "AddConstantValueColumn"; 00117 } 00118 std::string toString(bool verbose) const{ 00119 std::string result="AddConstantValueColumn"; 00120 if(verbose){ 00121 result+=" "; 00122 result+=col_name_; 00123 result+=" (Type: "; 00124 result+=util::getName(type_); 00125 result+=" Value: "; 00126 std::stringstream ss; 00127 ss << value_; 00128 result+=ss.str(); 00129 result+=")"; 00130 } 00131 return result; 00132 00133 } 00134 const std::string& getColumnName() { 00135 return col_name_; 00136 } 00137 00138 const AttributeType& getAttributeType() const { 00139 return type_; 00140 } 00141 const boost::any& getConstantValue() const { 00142 return value_; 00143 } 00144 00145 private: 00146 std::string col_name_; 00147 AttributeType type_; 00148 boost::any value_; 00149 }; 00150 00151 }//end namespace logical_operator 00152 00153 }//end namespace query_processing 00154 00155 }; //end namespace CogaDB