*** empty log message ***
[csql.git] / include / AggTableImpl.h
blob109ab0fa3467043ebab66bf72bd8c8c89eaa29cc
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 enum AggType
30 AGG_MIN = 1,
31 AGG_MAX,
32 AGG_SUM,
33 AGG_AVG,
34 AGG_COUNT,
35 AGG_UNKNOWN
37 #include<TableImpl.h>
38 class AggFldDef
40 public:
41 char fldName[IDENTIFIER_LENGTH];
42 DataType type;
43 int length;
44 void *bindBuf;
45 void *appBuf;
46 AggType atype;
47 bool alreadyBinded;
48 AggFldDef()
50 strcpy(fldName, "");
51 type=typeUnknown;
52 length=0;
53 bindBuf=NULL;
54 appBuf=NULL;
55 atype=AGG_UNKNOWN;
56 alreadyBinded=false;
59 class HashMapNode
61 public:
62 void *elem;
63 HashMapNode *next;
64 HashMapNode() { elem = NULL; next = NULL; }
66 class HashMap
68 void **bucket;
69 int keySize;
70 int bucketSize;
71 public:
72 HashMap(){ keySize = 0; bucketSize = 1009;
73 bucket = (void**) malloc(bucketSize * sizeof(void*));
74 memset(bucket, 0, bucketSize * sizeof(void*));
76 void setKeySize(int size);
77 DbRetVal insert(void *elem);
78 void* find(void *elem);
79 void removeAll();
82 class AggTableImpl:public Table
84 private:
85 char tblName_[IDENTIFIER_LENGTH];
86 void *curTuple; //holds the current tuple ptr. moved during fetch() calls
87 List fldList;
88 AggFldDef groupFld;
89 Table *tableHdl;
90 List aggNodes; //change this list to some other data structure
91 ListIterator aggNodeIter;
92 HashMap aggNodeMap; //for faster lookup
94 int aggNodeSize;
95 DbRetVal copyValuesToBindBuffer(void *tuple);
96 public:
97 AggTableImpl();
98 virtual ~AggTableImpl();
99 DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)
100 { return tableHdl->getFieldInfo(fieldName, info); }
101 bool isGroupSet()
103 if (groupFld.type == typeUnknown) return false; else return true;
105 void* insertOrGet();
106 void setTable(Table *impl){ tableHdl = impl;}
107 Table* getTableHdl(){ return tableHdl; }
108 DbRetVal closeScan();
109 void *getBindFldAddr(const char *name);
110 DbRetVal bindFld(const char *name, void *val);
111 DbRetVal bindFld(const char *name, AggType aggType, void *val);
112 DbRetVal setGroup(const char *name, void *val);
113 void setCondition(Condition *p){}
114 DbRetVal markFldNull(const char *name){}
115 DbRetVal markFldNull(int colpos){}
116 bool isFldNull(const char *name){return false;}
117 bool isFldNull(int colpos){return false;}
118 void clearFldNull(const char *name){}
119 void clearFldNull(int colpos){}
120 int getFldPos(char *name){}
121 void resetNullinfo(){}
122 DbRetVal insertTuple() { return ErrBadCall; }
123 DbRetVal updateTuple() { return ErrBadCall; }
124 DbRetVal deleteTuple() { return ErrBadCall; }
125 int deleteWhere() { return ErrBadCall; }
126 int truncate() { return ErrBadCall; }
127 long spaceUsed() { return 0; }
128 int pagesUsed() { return 0; }
129 DbRetVal lock(bool shared) { return ErrBadCall; }
130 DbRetVal unlock(){ return ErrBadCall; }
131 DbRetVal setUndoLogging(bool flag) { return ErrBadCall; }
132 void printSQLIndexString(){ };
133 char* getName() { return tableHdl->getName(); }
134 List getFieldNameList(){ List list; return list;}
135 DbRetVal execute();
136 void* fetch();
137 void* fetch(DbRetVal &rv);
138 void* fetchNoBind();
139 void* fetchNoBind(DbRetVal &rv);
140 DbRetVal close();
141 long numTuples();
142 void printInfo();
143 bool pushPredicate(Predicate *pred)
144 { printf("Wrong call\n"); return false; }
145 void setPredicate(Predicate *pred)
146 { printf("Wrong call\n"); }
147 bool isTableInvolved(char *tableName)
148 { printf("Wrong call\n"); return false; }
149 void printPlan(int space){printf("AGG-PLAN-TODO\n");}
150 DbRetVal optimize()
151 { printf("Wrong call\n"); return OK; }
152 ScanType getScanType(){ return unknownScan;}
153 bool hasIndex(char *fName){ return false;}
156 #endif