1 /* Copyright (C) 2014 InfiniDB, Inc. 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation; version 2 of 6 the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 MA 02110-1301, USA. */ 17 18 // $Id: expressionstep.h 9632 2013-06-18 22:18:20Z xlou $ 19 20 21 /** @file 22 * class ExpStep interface 23 */ 24 25 #ifndef JOBLIST_EXPRESSION_STEP_H 26 #define JOBLIST_EXPRESSION_STEP_H 27 28 //#define NDEBUG 29 #include "jobstep.h" 30 #include "filter.h" 31 32 33 namespace execplan 34 { 35 // forward reference 36 class ReturnedColumn; 37 class SimpleColumn; 38 class SimpleFilter; 39 class WindowFunctionColumn; 40 }; 41 42 43 namespace joblist 44 { 45 46 struct JobInfo; 47 struct FunctionJoinInfo; 48 49 class ExpressionStep : public JobStep 50 { 51 public: 52 // constructors 53 ExpressionStep(); 54 ExpressionStep(const JobInfo&); 55 // destructor constructors 56 virtual ~ExpressionStep(); 57 58 // inherited methods 59 void run(); 60 void join(); 61 const std::string toString() const; 62 oid()63 execplan::CalpontSystemCatalog::OID oid() const 64 { 65 return 0; 66 } tableOid()67 execplan::CalpontSystemCatalog::OID tableOid() const 68 { 69 return fTableOids.empty() ? 0 : fTableOids.front(); 70 } 71 using JobStep::alias; alias()72 std::string alias() const 73 { 74 return fAliases.empty() ? "" : fAliases.front(); 75 } 76 using JobStep::view; view()77 std::string view() const 78 { 79 return fViews.empty() ? "" : fViews.front(); 80 } 81 using JobStep::schema; schema()82 std::string schema() const 83 { 84 return fSchemas.empty() ? "" : fSchemas.front(); 85 } tableKey()86 uint32_t tableKey() const 87 { 88 return fTableKeys.empty() ? -1 : fTableKeys.front(); 89 } columnKey()90 uint32_t columnKey() const 91 { 92 return fColumnKeys.empty() ? -1 : fColumnKeys.front(); 93 } 94 95 void expression(const execplan::SRCP exp, JobInfo& jobInfo); expression()96 execplan::SRCP expression() const 97 { 98 return fExpression; 99 } 100 101 virtual void expressionFilter(const execplan::Filter* filter, JobInfo& jobInfo); 102 virtual void expressionFilter(const execplan::ParseTree* filter, JobInfo& jobInfo); expressionFilter()103 execplan::ParseTree* expressionFilter() const 104 { 105 return fExpressionFilter; 106 } 107 expressionId(uint64_t eid)108 void expressionId(uint64_t eid) 109 { 110 fExpressionId = eid; 111 } expressionId()112 uint64_t expressionId() const 113 { 114 return fExpressionId; 115 } 116 tableOids()117 const std::vector<execplan::CalpontSystemCatalog::OID>& tableOids() const 118 { 119 return fTableOids; 120 } aliases()121 const std::vector<std::string>& aliases() const 122 { 123 return fAliases; 124 } views()125 const std::vector<std::string>& views() const 126 { 127 return fViews; 128 } schemas()129 const std::vector<std::string>& schemas() const 130 { 131 return fSchemas; 132 } tableKeys()133 const std::vector<uint32_t>& tableKeys() const 134 { 135 return fTableKeys; 136 } columnKeys()137 const std::vector<uint32_t>& columnKeys() const 138 { 139 return fColumnKeys; 140 } 141 tableOids()142 std::vector<execplan::CalpontSystemCatalog::OID>& tableOids() 143 { 144 return fTableOids; 145 } aliases()146 std::vector<std::string>& aliases() 147 { 148 return fAliases; 149 } views()150 std::vector<std::string>& views() 151 { 152 return fViews; 153 } schemas()154 std::vector<std::string>& schemas() 155 { 156 return fSchemas; 157 } tableKeys()158 std::vector<uint32_t>& tableKeys() 159 { 160 return fTableKeys; 161 } columnKeys()162 std::vector<uint32_t>& columnKeys() 163 { 164 return fColumnKeys; 165 } 166 167 virtual void updateInputIndex(std::map<uint32_t, uint32_t>& indexMap, const JobInfo& jobInfo); 168 virtual void updateOutputIndex(std::map<uint32_t, uint32_t>& indexMap, const JobInfo& jobInfo); 169 virtual void updateColumnOidAlias(JobInfo& jobInfo); 170 columns()171 std::vector<execplan::ReturnedColumn*>& columns() 172 { 173 return fColumns; 174 } 175 void substitute(uint64_t, const SSC&); 176 selectFilter(bool b)177 void selectFilter(bool b) 178 { 179 fSelectFilter = b; 180 } selectFilter()181 bool selectFilter() const 182 { 183 return fSelectFilter; 184 } 185 associatedJoinId(uint64_t i)186 void associatedJoinId(uint64_t i) 187 { 188 fAssociatedJoinId = i; 189 } associatedJoinId()190 uint64_t associatedJoinId() const 191 { 192 return fAssociatedJoinId; 193 } 194 functionJoin(bool b)195 void functionJoin(bool b) 196 { 197 fDoJoin = b; 198 } functionJoin()199 bool functionJoin() const 200 { 201 return fDoJoin; 202 } 203 virtualStep(bool b)204 void virtualStep(bool b) 205 { 206 fVirtual = b; 207 } virtualStep()208 bool virtualStep() const 209 { 210 return fVirtual; 211 } 212 functionJoinInfo()213 boost::shared_ptr<FunctionJoinInfo>& functionJoinInfo() 214 { 215 return fFunctionJoinInfo; 216 } resetJoinInfo()217 void resetJoinInfo() 218 { 219 fFunctionJoinInfo.reset(); 220 } 221 222 protected: 223 virtual void addColumn(execplan::ReturnedColumn* rc, JobInfo& jobInfo); 224 virtual void addFilter(execplan::ParseTree* filter, JobInfo& jobInfo); 225 virtual void addSimpleFilter(execplan::SimpleFilter* sf, JobInfo& jobInfo); 226 virtual void populateColumnInfo(execplan::ReturnedColumn* rc, JobInfo& jobInfo); 227 virtual void populateColumnInfo(execplan::SimpleColumn* sc, JobInfo& jobInfo); 228 virtual void populateColumnInfo(execplan::WindowFunctionColumn* wc, JobInfo& jobInfo); 229 virtual void populateColumnInfo(execplan::AggregateColumn* ac, JobInfo& jobInfo); 230 virtual void functionJoinCheck(execplan::SimpleFilter* sf, JobInfo& jobInfo); 231 virtual bool parseFuncJoinColumn(ReturnedColumn* rc, JobInfo& jobInfo); 232 233 234 // expression 235 execplan::SRCP fExpression; 236 execplan::ParseTree* fExpressionFilter; 237 uint64_t fExpressionId; 238 239 // columns accessed 240 std::vector<execplan::CalpontSystemCatalog::OID> fTableOids; 241 std::vector<std::string> fAliases; 242 std::vector<std::string> fViews; 243 std::vector<std::string> fSchemas; 244 std::vector<uint32_t> fTableKeys; 245 std::vector<uint32_t> fColumnKeys; 246 std::vector<execplan::ReturnedColumn*> fColumns; 247 248 private: 249 // disable copy constructor 250 // Cannot copy fColumns, which depends on fExpressionFilter. 251 ExpressionStep(const ExpressionStep&); 252 253 // for VARBINARY, only support limited number of functions: like hex(), length(), etc. 254 bool fVarBinOK; 255 256 // @bug 3780, for select filter 257 bool fSelectFilter; 258 259 // @bug 3037, outer join with additional comparison 260 uint64_t fAssociatedJoinId; 261 262 // @bug 4531, for window function in IN/EXISTS sub-query. 263 std::map<execplan::SimpleColumn*, execplan::ReturnedColumn*> fSubMap; 264 std::set<SSC> fVsc; // for substitute wc with vsc 265 266 // @bug 3683, function join 267 boost::shared_ptr<FunctionJoinInfo> fFunctionJoinInfo; 268 bool fDoJoin; 269 bool fVirtual; 270 }; 271 272 } 273 274 #endif // JOBLIST_EXPRESSION_STEP_H 275 276