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: rowcolumn.cpp 6309 2010-03-04 19:33:12Z zzhu $
20 *
21 *
22 ***********************************************************************/
23
24 #include <iostream>
25 #include <string>
26 #include <exception>
27 #include <stdexcept>
28 #include <sstream>
29
30 using namespace std;
31
32 #include "bytestream.h"
33 using namespace messageqcpp;
34
35 #include "objectreader.h"
36 #include "calpontselectexecutionplan.h"
37
38 #include "rowgroup.h"
39 using namespace rowgroup;
40
41 #include "joblisttypes.h"
42 using namespace joblist;
43
44 #include "dataconvert.h"
45
46 #include "arithmeticcolumn.h"
47 #include "functioncolumn.h"
48 #include "simplefilter.h"
49 #include "aggregatecolumn.h"
50 #include "constantfilter.h"
51 #include "rowcolumn.h"
52
53 namespace execplan
54 {
55
56 /**
57 * Constructors/Destructors
58 */
RowColumn(const uint32_t sessionID)59 RowColumn::RowColumn(const uint32_t sessionID):
60 ReturnedColumn(sessionID)
61 {}
62
RowColumn(const RowColumn & rhs,const uint32_t sessionID)63 RowColumn::RowColumn (const RowColumn& rhs, const uint32_t sessionID):
64 ReturnedColumn(rhs, sessionID)
65 {
66 fColumnVec.clear();
67 //fColumnVec = rhs.fColumnVec;
68 SRCP srcp;
69
70 for (uint32_t i = 0; i < rhs.fColumnVec.size(); i++)
71 {
72 srcp.reset(rhs.fColumnVec[i]->clone());
73 fColumnVec.push_back(srcp);
74 }
75 }
76
~RowColumn()77 RowColumn::~RowColumn()
78 {}
79
80 /**
81 * Methods
82 */
83
operator =(const RowColumn & rhs)84 RowColumn& RowColumn::operator=(const RowColumn& rhs)
85 {
86 if (this != &rhs)
87 {
88 fColumnVec.clear();
89 fColumnVec = rhs.fColumnVec;
90 }
91
92 return *this;
93 }
94
operator <<(ostream & output,const RowColumn & rhs)95 ostream& operator<<(ostream& output, const RowColumn& rhs)
96 {
97 output << rhs.toString();
98
99 return output;
100 }
101
toString() const102 const string RowColumn::toString() const
103 {
104 ostringstream output;
105 output << "RowColumn" << endl;
106
107 for (uint32_t i = 0; i < fColumnVec.size(); i++)
108 output << fColumnVec[i]->toString();
109
110 return output.str();
111 }
112
serialize(messageqcpp::ByteStream & b) const113 void RowColumn::serialize(messageqcpp::ByteStream& b) const
114 {
115 b << (ObjectReader::id_t) ObjectReader::ROWCOLUMN;
116 ReturnedColumn::serialize(b);
117 b << (uint32_t)fColumnVec.size();
118
119 for (uint32_t i = 0; i < fColumnVec.size(); i++)
120 fColumnVec[i]->serialize(b);
121 }
122
unserialize(messageqcpp::ByteStream & b)123 void RowColumn::unserialize(messageqcpp::ByteStream& b)
124 {
125 fColumnVec.clear();
126 ObjectReader::checkType(b, ObjectReader::ROWCOLUMN);
127 ReturnedColumn::unserialize(b);
128 uint32_t size;
129 SRCP srcp;
130 b >> (uint32_t&)size;
131
132 for (uint32_t i = 0; i < size; i++)
133 {
134 srcp.reset(dynamic_cast<ReturnedColumn*>((ObjectReader::createTreeNode(b))));
135 fColumnVec.push_back(srcp);
136 }
137 }
138
operator ==(const RowColumn & t) const139 bool RowColumn::operator==(const RowColumn& t) const
140 {
141 if (fColumnVec.size() != t.columnVec().size())
142 return false;
143
144 for (uint32_t i = 0; i < fColumnVec.size(); i++)
145 {
146 if (fColumnVec[i].get() != NULL)
147 {
148 if (t.columnVec()[i].get() == NULL)
149 return false;
150
151 if (*(fColumnVec[i].get()) != t.columnVec()[i].get())
152 return false;
153 }
154 else if (t.columnVec()[i].get() != NULL)
155 return false;
156 }
157
158 return true;
159 }
160
operator ==(const TreeNode * t) const161 bool RowColumn::operator==(const TreeNode* t) const
162 {
163 const RowColumn* rc;
164
165 rc = dynamic_cast<const RowColumn*>(t);
166
167 if (rc == NULL)
168 return false;
169
170 return *this == *rc;
171 }
172
operator !=(const RowColumn & t) const173 bool RowColumn::operator!=(const RowColumn& t) const
174 {
175 return !(*this == t);
176 }
177
operator !=(const TreeNode * t) const178 bool RowColumn::operator!=(const TreeNode* t) const
179 {
180 return !(*this == t);
181 }
182
operator <<(ostream & output,const SubSelect & ss)183 ostream& operator<<(ostream& output, const SubSelect& ss)
184 {
185 output << ss.toString() << endl;
186 return output;
187 }
188
toString() const189 const string SubSelect::toString() const
190 {
191 return string(">SubSelect<");
192 }
193
194 } // namespace execplan
195