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: tdriver2.cpp 9210 2013-01-21 14:10:42Z rdempsey $
19 #include <iostream>
20 #include <string>
21 #include <sstream>
22 #include <iomanip>
23 using namespace std;
24 
25 #include "calpontsystemcatalog.h"
26 using namespace execplan;
27 
28 namespace
29 {
30 typedef CalpontSystemCatalog::OID OID_t;
31 typedef CalpontSystemCatalog::ColType ColType_t;
32 typedef CalpontSystemCatalog::ROPair ROPair_t;
33 
34 boost::shared_ptr<CalpontSystemCatalog> csc;
35 
toString(const string & tb,const string & col)36 string toString(const string& tb, const string& col)
37 {
38     ostringstream oss;
39 
40     OID_t colOID = csc->lookupOID(make_tcn("calpontsys", tb, col));
41     oss << tb << " " << setw(24) << col << " " << colOID;
42     ColType_t ct = csc->colType(colOID);
43     oss << " " << setw(4) << ct.colWidth << " " << setw(4) << ct.ddn.dictOID << " " << setw(2) << ct.colPosition;
44 
45     return oss.str();
46 }
47 
48 }
49 
main(int argc,char ** argv)50 int main(int argc, char** argv)
51 {
52     csc = CalpontSystemCatalog::makeCalpontSystemCatalog(0);
53     ROPair_t rp;
54 
55     string calpontsys("calpontsys");
56     string table;
57 
58     table = "systable";
59     rp = csc->tableRID(make_table(calpontsys, table));
60     cout << "   " << table << ": " << rp.objnum << endl;
61     cout << toString(table, "tablename") << endl;
62     cout << toString(table, "schema") << endl;
63     cout << toString(table, "objectid") << endl;
64     cout << toString(table, "createdate") << endl;
65     cout << toString(table, "lastupdate") << endl;
66     cout << toString(table, "init") << endl;
67     cout << toString(table, "next") << endl;
68     cout << toString(table, "numofrows") << endl;
69     cout << toString(table, "avgrowlen") << endl;
70     cout << toString(table, "numofblocks") << endl;
71     cout << toString(table, "autoincrement") << endl;
72     cout << endl;
73 
74     table = "syscolumn";
75     rp = csc->tableRID(make_table(calpontsys, table));
76     cout << "   " << table << ": " << rp.objnum << endl;
77     cout << toString(table, "schema") << endl;
78     cout << toString(table, "tablename") << endl;
79     cout << toString(table, "columnname") << endl;
80     cout << toString(table, "objectid") << endl;
81     cout << toString(table, "dictobjectid") << endl;
82     cout << toString(table, "listobjectid") << endl;
83     cout << toString(table, "treeobjectid") << endl;
84     cout << toString(table, "datatype") << endl;
85     cout << toString(table, "columnlength") << endl;
86     cout << toString(table, "columnposition") << endl;
87     cout << toString(table, "lastupdate") << endl;
88     cout << toString(table, "defaultvalue") << endl;
89     cout << toString(table, "nullable") << endl;
90     cout << toString(table, "scale") << endl;
91     cout << toString(table, "prec") << endl;
92     cout << toString(table, "autoincrement") << endl;
93     cout << toString(table, "distcount") << endl;
94     cout << toString(table, "nullcount") << endl;
95     cout << toString(table, "minvalue") << endl;
96     cout << toString(table, "maxvalue") << endl;
97     cout << toString(table, "compressiontype") << endl;
98     cout << toString(table, "nextvalue") << endl;
99     cout << endl;
100 #if 0
101     table = "sysindexcol";
102     rp = csc->tableRID(make_table(calpontsys, table));
103     cout << "   " << table << ": " << rp.objnum << endl;
104     cout << toString(table, "schema") << endl;
105     cout << toString(table, "tablename") << endl;
106     cout << toString(table, "columnname") << endl;
107     cout << toString(table, "indexname") << endl;
108     cout << toString(table, "columnposition") << endl;
109     cout << endl;
110 
111     table = "sysconstraint";
112     rp = csc->tableRID(make_table(calpontsys, table));
113     cout << "   " << table << ": " << rp.objnum << endl;
114     cout << toString(table, "constraintname") << endl;
115     cout << toString(table, "schema") << endl;
116     cout << toString(table, "tablename") << endl;
117     cout << toString(table, "constrainttype") << endl;
118     cout << toString(table, "constraintprimitive") << endl;
119     cout << toString(table, "constrainttext") << endl;
120     cout << toString(table, "constraintstatus") << endl;
121     cout << toString(table, "indexname") << endl;
122     cout << toString(table, "referencedtablename") << endl;
123     cout << toString(table, "referencedschema") << endl;
124     cout << toString(table, "referencedconstraintname") << endl;
125     cout << endl;
126 
127     table = "sysconstraintcol";
128     rp = csc->tableRID(make_table(calpontsys, table));
129     cout << "   " << table << ": " << rp.objnum << endl;
130     cout << toString(table, "schema") << endl;
131     cout << toString(table, "tablename") << endl;
132     cout << toString(table, "columnname") << endl;
133     cout << toString(table, "constraintname") << endl;
134     cout << endl;
135 
136     table = "sysindex";
137     rp = csc->tableRID(make_table(calpontsys, table));
138     cout << "   " << table << ": " << rp.objnum << endl;
139     cout << toString(table, "schema") << endl;
140     cout << toString(table, "tablename") << endl;
141     cout << toString(table, "indexname") << endl;
142     cout << toString(table, "listobjectid") << endl;
143     cout << toString(table, "treeobjectid") << endl;
144     cout << toString(table, "indextype") << endl;
145     cout << toString(table, "multicolflag") << endl;
146     cout << toString(table, "createdate") << endl;
147     cout << toString(table, "lastupdate") << endl;
148     cout << toString(table, "recordcount") << endl;
149     cout << toString(table, "treelevel") << endl;
150     cout << toString(table, "leafcount") << endl;
151     cout << toString(table, "distinctkeys") << endl;
152     cout << toString(table, "leafblocks") << endl;
153     cout << toString(table, "averageleafcountperkey") << endl;
154     cout << toString(table, "averagedatablockperkey") << endl;
155     cout << toString(table, "samplesize") << endl;
156     cout << toString(table, "clusterfactor") << endl;
157     cout << toString(table, "lastanalysisdate") << endl;
158     cout << endl;
159 #endif
160     return 0;
161 }
162 
163