allocator fixes
[csql.git] / include / AggTableImpl.h
blobd0d5ff506388b49056eddca56a5f59a6660c80b6
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 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 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);
111 return OK;
113 bool isFldNull(const char *name);
114 inline bool isFldNull(int colpos) {
115 if (colpos <= 32) { if (BITSET(prjNullInfo, colpos)) return true; }
116 else if (BITSET(*(int *)((char *)&prjNullInfo + 4), colpos)) return true;
117 return false;
119 void clearFldNull(const char *name){}
120 inline void clearFldNull(int colpos){
121 if (colpos <= 32) CLEARBIT(prjNullInfo, colpos);
122 else CLEARBIT(*(int *)((char*)&prjNullInfo + 4), colpos);
124 DbRetVal compact(){ return OK;}
125 int getFldPos(char *name){ return 0;}
126 void resetNullinfo(){}
127 DbRetVal insertTuple() { return ErrBadCall; }
128 DbRetVal updateTuple() { return ErrBadCall; }
129 DbRetVal deleteTuple() { return ErrBadCall; }
130 int deleteWhere() { return ErrBadCall; }
131 int truncate() { return ErrBadCall; }
132 long spaceUsed() { return 0; }
133 int pagesUsed() { return 0; }
134 DbRetVal lock(bool shared) { return ErrBadCall; }
135 DbRetVal unlock(){ return ErrBadCall; }
136 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
137 void printSQLIndexString(FILE *fp, int fd){ };
138 void printSQLForeignString(){}
139 char* getName() { return tableHdl->getName(); }
140 char* getAliasName(){ return tableHdl->getAliasName();}
141 List getFieldNameList(){ List list; return list;}
142 DbRetVal execute();
143 void* fetch();
144 void* fetch(DbRetVal &rv);
145 void* fetchNoBind();
146 void* fetchNoBind(DbRetVal &rv);
147 DbRetVal close();
148 long numTuples();
149 void printInfo();
150 bool pushPredicate(Predicate *pred)
151 { printf("Wrong call\n"); return false; }
152 void setPredicate(Predicate *pred)
153 { printf("Wrong call\n"); }
154 bool isTableInvolved(char *tableName)
155 { printf("Wrong call\n"); return false; }
156 void printPlan(int space);
157 DbRetVal optimize();
158 bool isFKTable(){return false;}
159 ScanType getScanType(){ return unknownScan;}
160 bool hasIndex(char *fName){ return false;}
161 AggType getAggType(const char *aggName, char *fldName);
164 #endif