1 /*
2    Copyright (c) 2017, MariaDB
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 #include <sstream>
21 #include <cstring>
22 
23 using namespace std;
24 
25 #include "bytestream.h"
26 using namespace messageqcpp;
27 
28 #include "rowgroup.h"
29 using namespace rowgroup;
30 
31 #include "joblisttypes.h"
32 using namespace joblist;
33 
34 #include "simplefilter.h"
35 #include "constantfilter.h"
36 #include "arithmeticcolumn.h"
37 #include "functioncolumn.h"
38 #include "objectreader.h"
39 #include "groupconcatcolumn.h"
40 #include "udafcolumn.h"
41 
42 namespace execplan
43 {
44 
45 /**
46  * Constructors/Destructors
47  */
UDAFColumn()48 UDAFColumn::UDAFColumn():
49     AggregateColumn()
50 {
51 }
52 
UDAFColumn(const uint32_t sessionID)53 UDAFColumn::UDAFColumn(const uint32_t sessionID):
54     AggregateColumn(sessionID)
55 {
56 }
57 
UDAFColumn(const UDAFColumn & rhs,const uint32_t sessionID)58 UDAFColumn::UDAFColumn(const UDAFColumn& rhs, const uint32_t sessionID):
59     AggregateColumn(dynamic_cast<const AggregateColumn&>(rhs), sessionID), context(rhs.context)
60 {
61 }
62 
~UDAFColumn()63 UDAFColumn::~UDAFColumn()
64 {
65 }
66 
67 /**
68  * Methods
69  */
70 
toString() const71 const string UDAFColumn::toString() const
72 {
73     ostringstream output;
74     output << "UDAFColumn " << endl;
75     output << AggregateColumn::toString() << endl;
76     output << context.toString() << endl;
77     return output.str();
78 }
79 
operator <<(ostream & output,const UDAFColumn & rhs)80 ostream& operator<<(ostream& output, const UDAFColumn& rhs)
81 {
82     output << rhs.toString();
83     return output;
84 }
85 
serialize(messageqcpp::ByteStream & b) const86 void UDAFColumn::serialize(messageqcpp::ByteStream& b) const
87 {
88     b << (uint8_t) ObjectReader::UDAFCOLUMN;
89     AggregateColumn::serialize(b);
90     context.serialize(b);
91 }
92 
unserialize(messageqcpp::ByteStream & b)93 void UDAFColumn::unserialize(messageqcpp::ByteStream& b)
94 {
95     ObjectReader::checkType(b, ObjectReader::UDAFCOLUMN);
96     AggregateColumn::unserialize(b);
97     context.unserialize(b);
98 }
99 
operator ==(const UDAFColumn & t) const100 bool UDAFColumn::operator==(const UDAFColumn& t) const
101 {
102     const AggregateColumn* rc1, *rc2;
103 
104     rc1 = static_cast<const AggregateColumn*>(this);
105     rc2 = static_cast<const AggregateColumn*>(&t);
106 
107     if (*rc1 != *rc2)
108         return false;
109 
110     if (context != t.context)
111         return false;
112 
113     return true;
114 }
115 
operator ==(const TreeNode * t) const116 bool UDAFColumn::operator==(const TreeNode* t) const
117 {
118     const UDAFColumn* ac;
119 
120     ac = dynamic_cast<const UDAFColumn*>(t);
121 
122     if (ac == NULL)
123         return false;
124 
125     return *this == *ac;
126 }
127 
operator !=(const UDAFColumn & t) const128 bool UDAFColumn::operator!=(const UDAFColumn& t) const
129 {
130     return !(*this == t);
131 }
132 
operator !=(const TreeNode * t) const133 bool UDAFColumn::operator!=(const TreeNode* t) const
134 {
135     return !(*this == t);
136 }
137 
138 } // namespace execplan
139