1 #ifndef _CEGOQUERYHELPER_H_INCLUDED_
2 #define _CEGOQUERYHELPER_H_INCLUDED_
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 // CegoQueryHelper.h
6 // -----------------
7 // Cego query helper
8 //
9 // Design and Implementation by Bjoern Lemke
10 //
11 // (C)opyright 2000-2019 Bjoern Lemke
12 //
13 // INTERFACE MODULE
14 //
15 // Class: CegoQueryHelper
16 //
17 // Description: The CegoQueryHelper class provides several utility methods with are used for tuple retrieval and evalution
18 //
19 // Status: CLEAN
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22 
23 // base includes
24 #include <lfcbase/ListT.h>
25 
26 // cego includes
27 #include "CegoAttrCond.h"
28 #include "CegoPredDesc.h"
29 #include "CegoCondDesc.h"
30 #include "CegoField.h"
31 #include "CegoFieldValue.h"
32 #include "CegoProcBlock.h"
33 #include "CegoExpr.h"
34 #include "CegoBlob.h"
35 #include "CegoClob.h"
36 #include "CegoTupleState.h"
37 #include "CegoAttrAlias.h"
38 #include "CegoAliasObject.h"
39 
40 class CegoQueryHelper {
41 
42 public:
43 
44     enum AttrCondMatch { INAPP, PARTIAL, COMPLETE };
45 
46     CegoQueryHelper();
47     ~CegoQueryHelper();
48 
49     // makes conjunctive normal form for the given condition
50     static void makeCNF(CegoCondDesc *pC);
51 
52     static void createConjunctionList(CegoPredDesc* pPred, ListT<CegoPredDesc*>* pConjunctionList);
53 
54     // evaluates the given predicate with the given join buffers and returns the logical result
55     static bool evalPredicate(ListT<CegoField>** pParentList,
56 		       int parentJoinBufPos,
57 		       ListT<CegoField>** pJoinBuf,
58 		       int pos,
59 		       CegoPredDesc* pP,
60 		       CegoProcBlock *pBlock = 0 );
61 
62     // filters a normalized attribute condition from the given predicate
63     static AttrCondMatch checkAttrCond(CegoAttrCond& ac,
64 		      CegoPredDesc* pP,
65 		      const ListT<CegoField>& schema,
66 		      ListT<CegoField>* flArray,
67 		      int flSize,
68 		      CegoProcBlock *pBlock);
69 
70     // internal debugging methods, not used by any class
71     static Chain condToChain(CegoCondDesc* pC, int depth);
72     static Chain predToChain(CegoPredDesc* pP, int depth);
73 
74     // for grouping and aggregation queries, these methods are used by CegoSelect and CegoGroupSpace
75     static void aggregateTuple(ListT<CegoField>& aggTuple, CegoExpr* pExpr);
76     static void aggregateTuple(ListT<CegoField>& aggTuple, CegoAggregation* pAgg);
77 
78     // the given field value is checked for type information of the given field and casted if required
79     static void prepareFieldValue(CegoField* pFV, CegoFieldValue& fv, CegoTableManager* pTM, int tabSetId);
80 
81 
82     static bool checkIndexForPredicate(int tabSetId, CegoDistManager* pGTM, CegoPredDesc *pPred, ListT<CegoContentObject*>& coList);
83 
84     // field list encoding and decoding methods
85     static void encodeFL(const ListT<CegoField>& fvl, char* &pBufBase, int &buflen);
86     static void decodeFL(ListT<CegoField>& fvl, char* pc, int len);
87 
88     static int encodeFVL(unsigned long long tid, unsigned long long tastep, CegoTupleState ts, const ListT<CegoField>& fvl, char* &pBufBase, int& buflen);
89     static int encodeFVL(unsigned long long tid, unsigned long long tastep, CegoTupleState ts, const ListT<CegoField>& fvl, const ListT<CegoBlob>& blobList, const ListT<CegoClob>& clobList, char* &pBufBase, int& buflen);
90 
91     static int skipTupleHeader();
92 
93     static int encodeTupleHeader(unsigned long long tid, unsigned long long tastep, CegoTupleState ts, char* p);
94     static int decodeTupleHeader(unsigned long long& tid, unsigned long long& tastep, CegoTupleState& ts, char* p);
95 
96     static void decodeFVL(ListT<CegoField>& fvl, char* pc, int len);
97     static void decodeFVL(ListT<CegoField>& fvl, ListT<CegoBlob>& blobList, ListT<CegoClob>& clobList, char* pc, int len);
98     static void decodeNativeFVL(ListT<CegoFieldValue>& fvl, ListT<CegoBlob>& blobList, ListT<CegoClob>& clobList, char* pc, int len);
99 
100     static void decodeUpdRec(Chain& tableAlias,
101 			     CegoPredDesc* &pPred,
102 			     ListT<CegoField>& updList,
103 			     ListT<CegoExpr*>& exprList,
104 			     bool& returnOnFirst,
105 			     char* pBuf, int buflen,
106 			     CegoDistManager* pGTM, int tabSetId);
107 
108     static void encodeUpdRec(const Chain& tableAlias,
109 			     CegoPredDesc* pPred,
110 			     const ListT<CegoField>& updList,
111 			     const ListT<CegoExpr*>& exprList,
112 			     const ListT<CegoBlob>& blobList,
113 			     const ListT<CegoClob>& clobList,
114 			     const bool returnOnFirst,
115 			     CegoProcBlock* pBlock,
116 			     char* &pBuf, int &buflen);
117 
118     static void decodeDelRec(Chain& tableAlias,
119 			     CegoPredDesc* &pPred,
120 			     char* pBuf, int buflen,
121 			     CegoDistManager *pGTM, int tabSetId);
122 
123     static void encodeDelRec(const Chain& tableAlias,
124 			     CegoPredDesc* pPred,
125 			     CegoProcBlock* pBlock,
126 			     char* &pBuf, int &buflen);
127 
128     static void mapAliasSchema(ListT<CegoField>& schema, const ListT<CegoAttrAlias>& aliasList);
129     static void mapAliasPredicate(CegoPredDesc* pPred, const Chain& tableAlias, const ListT<CegoAttrAlias>& aliasList);
130 
131     static CegoAttrCond mapAttrCond(const CegoAttrCond& attrCond, CegoAliasObject* pAO);
132 
133     static void mapFLA(ListT<CegoField>* pFLAmap, ListT<CegoField>** pFLA, int offset, int size, CegoAliasObject* pAO);
134     static void propFLA(ListT<CegoField>* pFLAprop, ListT<CegoField>** pFLA, int offset, int size, CegoAliasObject* pAO);
135 
136     static int maxFieldSize(CegoField *pF);
137 
138     static bool string2Clob(CegoFieldValue& fv, CegoTableManager* pTM, int tabSetId);
139 
140     static Chain skipComment(Chain& line);
141 
142 private:
143 
144     static bool evalFields(CegoComparison comp, const CegoFieldValue& f1, const CegoFieldValue& f2);
145     static bool evalBetween(const CegoFieldValue& f1, const CegoFieldValue& f2, const CegoFieldValue& f3);
146 
147     static void createConjunctionList(CegoPredDesc* pPred, ListT<CegoPredDesc*>& conjunctionList);
148 
149 
150     static AttrCondMatch evalAttrCond(CegoAttrCond& ac,
151 		      CegoPredDesc* pP,
152 		      const ListT<CegoField>& schema,
153 		      ListT<CegoField>* flArray,
154 		      int flSize,
155 		      CegoProcBlock *pBlock);
156 
157     static AttrCondMatch evalAttrCondbyCondition(CegoAttrCond& ac,
158 					  CegoCondDesc* pC,
159 					  const ListT<CegoField>& schema,
160 					  ListT<CegoField>* flArray,
161 					  int flSize,
162 					  CegoProcBlock* pBlock);
163 
164     static int max(int i1, int i2, int i3, int i4);
165 };
166 
167 #endif
168