Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
unary_operator.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 //#include <core/scheduling_decision.hpp>
00004 
00005 //#include <boost/shared_ptr.hpp>
00006 #include <config/global_definitions.hpp>
00007 #include <config/configuration.hpp>
00008 #include <query_processing/typed_operator.hpp>
00009 
00010 namespace hype {
00011     namespace queryprocessing {
00012 
00013         template <typename OperatorInputType, typename OperatorOutputType> //, typename TLogicalOperation>
00014         class UnaryOperator : public TypedOperator<OperatorOutputType> { //uses 1D Learning Method
00015 
00016         public:
00017             //typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedOperator TypedOperator;
00018             typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedOperatorPtr TypedOperatorPtr;
00019             //typedef typename OperatorMapper_Helper_Template<OperatorOutputType>::TypedNodePtr TypedNodePtr;
00020 
00021             //typedef TLogicalOperation LogicalOperationType;
00022 
00023             UnaryOperator(const hype::SchedulingDecision& sched_dec, TypedOperatorPtr child)
00024             : TypedOperator<OperatorOutputType>(sched_dec), child_(child) {
00025             }
00026 
00027             virtual ~UnaryOperator() {
00028             }
00029 
00030             OperatorInputType getInputData() {
00031                 if (child_)
00032                     return child_->getResult();
00033                 else
00034                     return OperatorInputType();
00035             }
00036 
00037             virtual bool run() {
00038 
00039                 if (!hype::core::Runtime_Configuration::instance().isQueryChoppingEnabled() && child_) {
00040                     child_->run();
00041                 }
00042                 //execute this operator
00043                 double begin = double(hype::core::getTimestamp());
00044                 timeEstimated = double(this->getEstimatedExecutionTime().getTimeinNanoseconds());
00045                 bool retVal = (*this)();
00046                 timeNeeded = double( hype::core::getTimestamp()) - begin;
00047                 return retVal;
00048             }
00049 
00050             virtual void print(unsigned int tree_level) const {
00051                 for (unsigned int i = 0; i < tree_level; ++i) {
00052                     std::cout << "\t";
00053                 }
00054                 assert(!this->getFeatureValues().empty());
00055                 std::cout << this->getAlgorithmName() << " ET: " << this->getEstimatedExecutionTime().getTimeinNanoseconds()
00056                         << "\tEC: " << this->getFeatureValues()[0]
00057                         << std::endl; // << " Features: " << this->getFeatureValues() << std::endl;
00058                 if (child_) child_->print(tree_level + 1);
00059             }
00060 
00061             virtual void printResult(unsigned int tree_level) const {
00062                 for (unsigned int i = 0; i < tree_level; ++i) {
00063                     std::cout << "\t";
00064                 }
00065                 assert(!this->getFeatureValues().empty());
00066                 std::cout << this->getAlgorithmName() << " ET: " << timeEstimated
00067                         << "\tMT: " << timeNeeded
00068                         << "\tEE: " << 1 - (timeEstimated / timeNeeded)
00069                         << "\tEC: " << this->getFeatureValues()[0];
00070                 if (this->getResultSize() != -1) {
00071                     std::cout << "\tRR: " << this->getResultSize();
00072                 }
00073                         std::cout << std::endl;
00074                 if (child_) child_->printResult(tree_level + 1);
00075             }
00076 
00077             virtual double getRecursiveExecutionTimeInNanoseconds() {
00078                 double executiontime = this->getEstimatedExecutionTime().getTimeinNanoseconds();
00079                 if (executiontime < 0) {
00080                     executiontime = 0;
00081                 }
00082                 if (child_) {
00083                     executiontime += child_->getRecursiveExecutionTimeInNanoseconds();
00084                 }
00085                 return executiontime;
00086             }
00087 
00088             /*
00089             virtual std::list<TypedOperator<OperatorOutputType>& > getOperatorQueue(){
00090                     std::list<TypedOperator<OperatorOutputType>& > list = child_->getOperatorQueue();
00091                     list.push_front(*this);
00092                     return list;
00093             }*/
00094         private:
00095             double timeNeeded;
00096             double timeEstimated;
00097 
00098             boost::shared_ptr<TypedOperator<OperatorInputType> > child_;
00099             //boost::shared_ptr<TypedOperator<OperatorOutputType> > succsessor_;
00100         };
00101 
00102     }; //end namespace queryprocessing
00103 }; //end namespace hype
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines