code reorg
[csql.git] / include / AggTableImpl.h
blob5ab7f7de4e21be5d308a9379bfd40c1af12560a2
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef AGGTABLE_IMPL_H
17 #define AGGTABLE_IMPL_H
18 #include<os.h>
19 #include<DataType.h>
20 #include<Transaction.h>
21 #include<Database.h>
22 #include<Index.h>
23 #include<CatalogTables.h>
24 #include<Info.h>
25 #include<Debug.h>
26 #include<DatabaseManagerImpl.h>
27 #include<Predicate.h>
28 #include<HeapAllocator.h>
29 #ifndef AGGTYPE
30 enum AggType
32 AGG_MIN = 1,
33 AGG_MAX,
34 AGG_SUM,
35 AGG_AVG,
36 AGG_COUNT,
37 AGG_UNKNOWN
40 #define AGGTYPE
41 #endif
42 #include<TableImpl.h>
43 class DllExport AggFldDef
45 public:
46 char fldName[IDENTIFIER_LENGTH];
47 DataType type;
48 int length;
49 void *bindBuf;
50 void *appBuf;
51 AggType aType;
52 bool alreadyBinded;
53 bool isNullable;
54 AggFldDef()
56 strcpy(fldName, "");
57 type=typeUnknown;
58 length=0;
59 bindBuf=NULL;
60 appBuf=NULL;
61 aType=AGG_UNKNOWN;
62 alreadyBinded=false;
63 isNullable=false;
67 class DllExport AggTableImpl:public Table
69 private:
70 char tblName_[IDENTIFIER_LENGTH];
71 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
72 List fldList;
73 List fldGroupList;
74 Table *tableHdl;
75 List aggNodes; //change this list to some other data structure
76 ListIterator aggNodeIter;
77 HashMap aggNodeMap; //for faster lookup
78 Predicate *havingPred;
79 int grpNullInfo;
80 long long prjNullInfo;
81 int aggNodeSize;
82 int groupSize;
83 char *grpFldBuffer;
85 bool optGrpIntNoNull;
86 void *grpBindBuf;
88 DbRetVal copyValuesToBindBuffer(void *tuple);
89 public:
90 AggTableImpl();
91 virtual ~AggTableImpl();
92 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
93 { return tableHdl->getFieldInfo(fieldName, info); }
94 void* insertOrGetAggNode();
95 void setTable(Table *impl){ tableHdl = impl;}
96 Table* getTableHdl(){ return tableHdl; }
97 DbRetVal closeScan();
98 void *getBindFldAddr(const char *name);
99 DbRetVal bindFld(const char *name, void *val, bool dummy=false);
100 DbRetVal bindFld(const char *name, AggType aggType, void *val);
101 DbRetVal setGroup(const char *name, void *val);
102 bool isFldPresentInGrp(char *fname);
103 int computeGrpNodeSize();
104 void* getGroupValueBuffer();
105 int getAggOffset(char *fname, AggType aggType);
106 DbRetVal copyValuesFromGrpBindBuf(char *grpFldBuf, char *fldName);
107 void setCondition(Condition *p){ havingPred = p->getPredicate();}
108 DbRetVal markFldNull(const char *name){ return OK;}
109 inline DbRetVal markFldNull(int colpos){
110 SETBIT(grpNullInfo, colpos-1);
111 return OK;
113 bool isFldNull(const char *name);
114 inline bool isFldNull(int colpos) {
115 if (colpos <= 32) { if (BITSET(prjNullInfo, colpos-1)) return true; }
116 else if (BITSET(*(int *)((char *)&prjNullInfo + 4), colpos-1))
117 return true;
118 return false;
120 void clearFldNull(const char *name){}
121 inline void clearFldNull(int colpos){
122 if (colpos <= 32) CLEARBIT(prjNullInfo, colpos-1);
123 else CLEARBIT(*(int *)((char*)&prjNullInfo + 4), colpos-1);
125 DbRetVal compact(){ return OK;}
126 int getFldPos(char *name){ return 0;}
127 void resetNullinfo(){}
128 DbRetVal insertTuple() { return ErrBadCall; }
129 DbRetVal updateTuple() { return ErrBadCall; }
130 DbRetVal deleteTuple() { return ErrBadCall; }
131 int deleteWhere() { return ErrBadCall; }
132 int truncate() { return ErrBadCall; }
133 long spaceUsed() { return 0; }
134 int pagesUsed() { return 0; }
135 DbRetVal lock(bool shared) { return ErrBadCall; }
136 DbRetVal unlock(){ return ErrBadCall; }
137 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
138 void printSQLIndexString(FILE *fp, int fd){ };
139 void printSQLForeignString(){}
140 char* getName() { return tableHdl->getName(); }
141 char* getAliasName(){ return tableHdl->getAliasName();}
142 List getFieldNameList(){ List list; return list;}
143 DbRetVal execute();
144 void* fetch();
145 void* fetch(DbRetVal &rv);
146 void* fetchNoBind();
147 void* fetchNoBind(DbRetVal &rv);
148 DbRetVal close();
149 long numTuples();
150 void printInfo();
151 bool pushPredicate(Predicate *pred)
152 { printf("Wrong call\n"); return false; }
153 void setPredicate(Predicate *pred)
154 { printf("Wrong call\n"); }
155 bool isTableInvolved(char *tableName)
156 { printf("Wrong call\n"); return false; }
157 void printPlan(int space);
158 DbRetVal optimize();
159 bool isFKTable(){return false;}
160 ScanType getScanType(){ return unknownScan;}
161 bool hasIndex(char *fName){ return false;}
162 AggType getAggType(const char *aggName, char *fldName);
165 #endif