*** empty log message ***
[csql.git] / include / AggTableImpl.h
blob1f5d48c67b6ed8713c597c4e510326aded1aa5b9
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 DbRetVal getQualifiedName(const char *fieldName, char *qualName)
95 { return tableHdl->getQualifiedName(fieldName, qualName); }
96 void* insertOrGetAggNode();
97 void setTable(Table *impl){ tableHdl = impl;}
98 Table* getTableHdl(){ return tableHdl; }
99 DbRetVal closeScan();
100 void *getBindFldAddr(const char *name);
101 DbRetVal bindFld(const char *name, void *val, bool dummy=false);
102 DbRetVal bindFld(const char *name, AggType aggType, void *val);
103 DbRetVal setGroup(const char *name, void *val);
104 bool isFldPresentInGrp(char *fname);
105 int computeGrpNodeSize();
106 void* getGroupValueBuffer();
107 int getAggOffset(char *fname, AggType aggType);
108 DbRetVal copyValuesFromGrpBindBuf(char *grpFldBuf, char *fldName);
109 void setCondition(Condition *p){ havingPred = p->getPredicate();}
110 DbRetVal markFldNull(const char *name){ return OK;}
111 inline DbRetVal markFldNull(int colpos){
112 SETBIT(grpNullInfo, colpos-1);
113 return OK;
115 bool isFldNull(const char *name);
116 inline bool isFldNull(int colpos) {
117 if (colpos <= 32) { if (BITSET(prjNullInfo, colpos-1)) return true; }
118 else if (BITSET(*(int *)((char *)&prjNullInfo + 4), colpos-1))
119 return true;
120 return false;
122 void clearFldNull(const char *name){}
123 inline void clearFldNull(int colpos){
124 if (colpos <= 32) CLEARBIT(prjNullInfo, colpos-1);
125 else CLEARBIT(*(int *)((char*)&prjNullInfo + 4), colpos-1);
127 DbRetVal compact(){ return OK;}
128 int getFldPos(char *name){ return 0;}
129 void resetNullinfo(){}
130 DbRetVal insertTuple() { return ErrBadCall; }
131 DbRetVal updateTuple() { return ErrBadCall; }
132 DbRetVal deleteTuple() { return ErrBadCall; }
133 int deleteWhere() { return ErrBadCall; }
134 int truncate() { return ErrBadCall; }
135 long spaceUsed() { return 0; }
136 int pagesUsed() { return 0; }
137 DbRetVal lock(bool shared) { return ErrBadCall; }
138 DbRetVal unlock(){ return ErrBadCall; }
139 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
140 void printSQLIndexString(FILE *fp, int fd){ };
141 void printSQLForeignString(){}
142 char* getName() { return tableHdl->getName(); }
143 char* getAliasName(){ return tableHdl->getAliasName();}
144 List getFieldNameList(){ List list; return list;}
145 DbRetVal execute();
146 void* fetch();
147 void* fetch(DbRetVal &rv);
148 void* fetchNoBind();
149 void* fetchNoBind(DbRetVal &rv);
150 DbRetVal close();
151 long numTuples();
152 void printInfo();
153 bool pushPredicate(Predicate *pred)
154 { printf("Wrong call\n"); return false; }
155 void setPredicate(Predicate *pred)
156 { printf("Wrong call\n"); }
157 bool isTableInvolved(char *tableName)
158 { printf("Wrong call\n"); return false; }
159 void printPlan(int space);
160 DbRetVal optimize();
161 bool isFKTable(){return false;}
162 ScanType getScanType(){ return unknownScan;}
163 bool hasIndex(char *fName){ return false;}
164 AggType getAggType(const char *aggName, char *fldName);
167 #endif