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: treenode.cpp 9317 2013-03-19 21:37:22Z dhall $
20 *
21 *
22 ***********************************************************************/
23 /** @file */
24 
25 #include <unistd.h>
26 #include <string>
27 #include <exception>
28 #include <typeinfo>
29 #include <cstring>
30 
31 #include "bytestream.h"
32 #include "treenode.h"
33 #include "objectreader.h"
34 
35 using namespace std;
36 namespace execplan
37 {
38 
39 /**
40  * Constructors/Destructors
41  */
TreeNode()42 TreeNode::TreeNode(): fDerivedTable(""),
43     fRefCount(0),
44     fDerivedRefCol(NULL)
45 {
46     memset(tmp, 0, 312);
47 }
48 
TreeNode(const TreeNode & rhs)49 TreeNode::TreeNode(const TreeNode& rhs):
50     fResult(rhs.fResult),
51     fResultType(rhs.resultType()),
52     fOperationType(rhs.operationType()),
53     fDerivedTable (rhs.derivedTable()),
54     fRefCount(rhs.refCount()),
55     fDerivedRefCol(rhs.derivedRefCol())
56 {
57     memcpy(tmp, rhs.tmp, 312);
58 }
59 
~TreeNode()60 TreeNode::~TreeNode() {}
61 
resultType(const execplan::CalpontSystemCatalog::ColType & resultType)62 void TreeNode::resultType ( const execplan::CalpontSystemCatalog::ColType& resultType)
63 {
64     fResultType = resultType;
65 
66     // set scale/precision for the result
67     if (fResultType.colDataType == execplan::CalpontSystemCatalog::DECIMAL ||
68             fResultType.colDataType == execplan::CalpontSystemCatalog::UDECIMAL)
69     {
70         fResult.decimalVal.scale = fResultType.scale;
71         fResult.decimalVal.precision = fResultType.precision;
72     }
73 }
74 
75 /**
76  * ostream function
77  */
operator <<(ostream & output,const TreeNode & rhs)78 ostream& operator<<(ostream& output, const TreeNode& rhs)
79 {
80     output << rhs.toString();
81     return output;
82 }
83 
84 }  /* namespace */
85