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 /***********************************************************************
19 *   $Id: selectfilter.h 9210 2013-01-21 14:10:42Z rdempsey $
20 *
21 *
22 ***********************************************************************/
23 /** @file */
24 
25 #ifndef SELECTFILTER_H
26 #define SELECTFILTER_H
27 #include <string>
28 
29 #include "filter.h"
30 #include "returnedcolumn.h"
31 #include "operator.h"
32 #include "calpontselectexecutionplan.h"
33 
34 /**
35  * Namespace
36  */
37 namespace execplan
38 {
39 /**
40  * @brief A class to represent a subselect predicate
41  *
42  * This class is a specialization of class Filter that handles a
43  * subselect predicate like "col1 = (select col2 from table2)"
44  */
45 class SelectFilter : public Filter
46 {
47     /**
48      * Public stuff
49      */
50 public:
51 
52     /**
53      * Constructors / copy constructor
54      */
55     SelectFilter();
56     SelectFilter(const SelectFilter& rhs);
57 
58     /** Constructors
59      *
60      * pass all parts in ctor
61      * @note SimpleFilter takes ownership of all these pointers
62      */
63     SelectFilter(const std::vector<SRCP>& cols, const SOP& op, SCSEP& sub, bool correlated = false);
64 
65     /**
66      * Destructors
67      */
68     virtual ~SelectFilter();
69 
70     /**
71      * Accessor Methods
72      */
cols()73     inline const std::vector<SRCP>& cols() const
74     {
75         return fCols;
76     }
77 
cols(const std::vector<SRCP> & cols)78     void cols(const std::vector<SRCP>& cols)
79     {
80         fCols = cols;
81     }
82 
op()83     inline const SOP& op() const
84     {
85         return fOp;
86     }
87 
op(const SOP & op)88     inline void op (const SOP& op)
89     {
90         fOp = op;
91     }
92 
sub()93     inline const SCSEP& sub() const
94     {
95         return fSub;
96     }
97 
sub(SCSEP & sub)98     inline void sub(SCSEP& sub)
99     {
100         fSub = sub;
101     }
102 
correlated()103     bool correlated() const
104     {
105         return fCorrelated;
106     }
correlated(const bool correlated)107     void correlated(const bool correlated)
108     {
109         fCorrelated = correlated;
110     }
111 
112     virtual const std::string toString() const;
113 
data()114     virtual inline const std::string data() const
115     {
116         return fData;
117     }
data(const std::string data)118     virtual inline void data( const std::string data )
119     {
120         fData = data;
121     }
122 
returnedColPos()123     uint64_t returnedColPos() const
124     {
125         return fReturnedColPos;
126     }
returnedColPos(const uint64_t returnedColPos)127     void returnedColPos(const uint64_t returnedColPos)
128     {
129         fReturnedColPos = returnedColPos;
130     }
131 
132     /**
133      * The serialization interface
134      */
135     virtual void serialize(messageqcpp::ByteStream&) const;
136     virtual void unserialize(messageqcpp::ByteStream&);
137 
138     /** return a copy of this pointer
139      *
140      * deep copy of this pointer and return the copy
141      */
clone()142     inline virtual SelectFilter* clone() const
143     {
144         return new SelectFilter (*this);
145     }
146 
147     /** @brief Do a deep, strict (as opposed to semantic) equivalence test
148      *
149      * Do a deep, strict (as opposed to semantic) equivalence test.
150      * @return true iff every member of t is a duplicate copy of every member of this; false otherwise
151      */
152     virtual bool operator==(const TreeNode* t) const;
153 
154     /** @brief Do a deep, strict (as opposed to semantic) equivalence test
155      *
156      * Do a deep, strict (as opposed to semantic) equivalence test.
157      * @return true iff every member of t is a duplicate copy of every member of this; false otherwise
158      */
159     bool operator==(const SelectFilter& t) const;
160 
161     /** @brief Do a deep, strict (as opposed to semantic) equivalence test
162      *
163      * Do a deep, strict (as opposed to semantic) equivalence test.
164      * @return false iff every member of t is a duplicate copy of every member of this; true otherwise
165      */
166     virtual bool operator!=(const TreeNode* t) const;
167 
168     /** @brief Do a deep, strict (as opposed to semantic) equivalence test
169      *
170      * Do a deep, strict (as opposed to semantic) equivalence test.
171      * @return false iff every member of t is a duplicate copy of every member of this; true otherwise
172      */
173     bool operator!=(const SelectFilter& t) const;
174 
175 private:
176     //default okay?
177     //SelectFilter& operator=(const SelectFilter& rhs);
178 
179     std::vector<SRCP> fCols;
180     SOP fOp;
181     SCSEP fSub;
182     bool fCorrelated;
183     std::string fData;
184     uint64_t fReturnedColPos;	// offset in fSub->returnedColList to indicate the start of projection
185 };
186 
187 std::ostream& operator<<(std::ostream& output, const SelectFilter& rhs);
188 
189 }
190 #endif //SELECTFILTER_H
191 
192