1 /* Copyright (C) 2014 InfiniDB, Inc. 2 Copyright (C) 2019 MariaDB Corporation 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; version 2 of 7 the License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 MA 02110-1301, USA. */ 18 19 /*********************************************************************** 20 * $Id: operator.h 9635 2013-06-19 21:42:30Z bwilkinson $ 21 * 22 * 23 ***********************************************************************/ 24 /** @file */ 25 26 #ifndef OPERATOR_H 27 #define OPERATOR_H 28 #include <string> 29 #include <iosfwd> 30 #include <boost/shared_ptr.hpp> 31 32 #include "treenode.h" 33 34 namespace messageqcpp 35 { 36 class ByteStream; 37 } 38 39 namespace execplan 40 { 41 class ParseTree; 42 class ReturnedColumn; 43 44 enum OpType 45 { 46 OP_ADD = 0, 47 OP_SUB, 48 OP_MUL, 49 OP_DIV, 50 OP_EQ, 51 OP_NE, 52 OP_GT, 53 OP_GE, 54 OP_LT, 55 OP_LE, 56 OP_LIKE, 57 OP_NOTLIKE, 58 OP_AND, 59 OP_OR, 60 OP_ISNULL, 61 OP_ISNOTNULL, 62 OP_BETWEEN, 63 OP_NOTBETWEEN, 64 OP_IN, 65 OP_NOTIN, 66 OP_XOR, 67 OP_UNKNOWN, 68 }; 69 70 class Operator : public TreeNode 71 { 72 73 public: 74 Operator(); 75 Operator(const std::string& operatorName); 76 Operator(const Operator& rhs); 77 78 virtual ~Operator(); 79 80 virtual const std::string toString() const; data()81 virtual const std::string data() const 82 { 83 return fData; 84 } 85 virtual void data(const std::string data); 86 87 /** return a copy of this pointer 88 * 89 * deep copy of this pointer and return the copy 90 */ clone()91 inline virtual Operator* clone() const 92 { 93 return new Operator (*this); 94 } 95 96 /** return the opposite operator 97 * @note this is not a compliment of operator. this is for the case that 98 * the two operands of operator get switched, and the operator needs to 99 * be reversed. e.g., where C1 > C2 ==> where C2 < C1 100 */ 101 virtual Operator* opposite() const; 102 103 /** 104 * The serialization interface 105 */ 106 virtual void serialize(messageqcpp::ByteStream&) const; 107 virtual void unserialize(messageqcpp::ByteStream&); 108 109 /** @brief Do a deep, strict (as opposed to semantic) equivalence test 110 * 111 * Do a deep, strict (as opposed to semantic) equivalence test. 112 * @return true iff every member of t is a duplicate copy of every member of this; false otherwise 113 */ 114 virtual bool operator==(const TreeNode* t) const; 115 116 /** @brief Do a deep, strict (as opposed to semantic) equivalence test 117 * 118 * Do a deep, strict (as opposed to semantic) equivalence test. 119 * @return true iff every member of t is a duplicate copy of every member of this; false otherwise 120 */ 121 bool operator==(const Operator& t) const; 122 123 /** @brief Do a deep, strict (as opposed to semantic) equivalence test 124 * 125 * Do a deep, strict (as opposed to semantic) equivalence test. 126 * @return false iff every member of t is a duplicate copy of every member of this; true otherwise 127 */ 128 virtual bool operator!=(const TreeNode* t) const; 129 130 /** @brief Do a deep, strict (as opposed to semantic) equivalence test 131 * 132 * Do a deep, strict (as opposed to semantic) equivalence test. 133 * @return false iff every member of t is a duplicate copy of every member of this; true otherwise 134 */ 135 bool operator!=(const Operator& t) const; 136 137 /** @breif reverse the operator 138 * 139 * Literally reverse the operator, as left operand and right operand are swapped, or a NOT 140 * is applied before the operator 141 */ 142 virtual void reverseOp(); 143 144 protected: 145 std::string fData; 146 147 /*********************************************************** 148 * F&E framework * 149 ***********************************************************/ 150 public: op()151 virtual OpType op() const 152 { 153 return fOp; 154 } op(const OpType op)155 virtual void op(const OpType op) 156 { 157 fOp = op; 158 } 159 using TreeNode::evaluate; evaluate(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)160 virtual void evaluate(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) {} 161 162 // The following methods should be pure virtual. Currently too many instanslization exists. 163 using TreeNode::getStrVal; getStrVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)164 virtual const std::string& getStrVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 165 { 166 return fResult.strVal; 167 } 168 using TreeNode::getIntVal; getIntVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)169 virtual int64_t getIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 170 { 171 return fResult.intVal; 172 } 173 using TreeNode::getUintVal; getUintVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)174 virtual uint64_t getUintVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 175 { 176 return fResult.uintVal; 177 } 178 using TreeNode::getFloatVal; getFloatVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)179 virtual float getFloatVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 180 { 181 return fResult.floatVal; 182 } 183 using TreeNode::getDoubleVal; getDoubleVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)184 virtual double getDoubleVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 185 { 186 return fResult.doubleVal; 187 } 188 using TreeNode::getLongDoubleVal; getLongDoubleVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)189 virtual long double getLongDoubleVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 190 { 191 return fResult.longDoubleVal; 192 } 193 using TreeNode::getDecimalVal; getDecimalVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)194 virtual IDB_Decimal getDecimalVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 195 { 196 return fResult.decimalVal; 197 } 198 using TreeNode::getDateIntVal; getDateIntVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)199 virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 200 { 201 return fResult.intVal; 202 } 203 using TreeNode::getDatetimeIntVal; getDatetimeIntVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)204 virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 205 { 206 return fResult.intVal; 207 } 208 using TreeNode::getTimestampIntVal; getTimestampIntVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)209 virtual int64_t getTimestampIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 210 { 211 return fResult.intVal; 212 } 213 using TreeNode::getTimeIntVal; getTimeIntVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)214 virtual int64_t getTimeIntVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 215 { 216 return fResult.intVal; 217 } 218 using TreeNode::getBoolVal; getBoolVal(rowgroup::Row & row,bool & isNull,ParseTree * lop,ParseTree * rop)219 virtual bool getBoolVal(rowgroup::Row& row, bool& isNull, ParseTree* lop, ParseTree* rop) 220 { 221 return fResult.boolVal; 222 } getBoolVal(rowgroup::Row & row,bool & isNull,ReturnedColumn * lop,ReturnedColumn * rop)223 virtual bool getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedColumn* lop, ReturnedColumn* rop) 224 { 225 return fResult.boolVal; 226 } 227 setOpType(Type & l,Type & r)228 virtual void setOpType(Type& l, Type& r) {} operationType(const Type & ot)229 virtual void operationType(const Type& ot) 230 { 231 fOperationType = ot; 232 } operationType()233 virtual const Type& operationType() const 234 { 235 return fOperationType; 236 } 237 238 protected: 239 OpType fOp; 240 }; 241 242 typedef boost::shared_ptr<Operator> SOP; 243 244 std::ostream& operator<<(std::ostream& os, const Operator& rhs); 245 } 246 247 248 #endif //OPERATOR_H 249 250