-
Notifications
You must be signed in to change notification settings - Fork 1
/
monq_structures.h
262 lines (217 loc) · 5.41 KB
/
monq_structures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#ifndef _MONQ_STRUCTURES_H_
#define _MONQ_STRUCTURES_H_
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "nodes/pg_list.h"
#include "utils/builtins.h"
#include "utils/jsonb.h"
typedef enum TypeOfLeafValue
{
S,
I,
A,
D,
B
} TypeOfLeafValue;
typedef enum TypeOfOperator
{
NOP,
MOP,
AOP,
VOP,
EOP
} TypeOfOperator;
typedef enum ArrayOperatorType
{
_IN,
_NIN,
_ALL
} ArrayOperatorType;
typedef enum ExpressionOperatorType
{
_OR,
_NOR,
_AND
} ExpressionOperatorType;
typedef enum ValueOperatorType
{
_LESS,
_EQ,
_NOTEQ,
_LESSEQ,
_GREAT,
_GREATEQ,
_TYPE,
_SIZE,
_EXISTS
} ValueOperatorType;
typedef enum TypeOfClause
{
LEAF,
COMMENT,
TEXT,
WHERE,
EXPRESSION
} TypeOfClause;
typedef enum TypeOfValue
{
LF_VALUE,
OP_OBJECT
} TypeOfValue;
typedef enum TypeOfElemMatchValue
{
E_EXPRESSION,
E_OP_OBJECT
} TypeOfElemMatchValue;
typedef enum TypeOfWhereClauseValue
{
STR
} TypeOfWhereClauseValue;
typedef struct MArray
{
List *arrayList;
} MArray;
typedef struct LeafValue
{
TypeOfLeafValue type;
union
{
char *str;
char *i;
MArray *ar;
bool b;
char *d;
};
} LeafValue;
/* Operators */
typedef struct ValueOperator
{
TypeOfOperator type;
ValueOperatorType value_op;
LeafValue *value;
} ValueOperator;
typedef struct NotOperator
{
TypeOfOperator type;
struct Operator *op;
} NotOperator;
typedef struct ArrayOperator
{
TypeOfOperator type;
ArrayOperatorType array_op;
MArray *ar;
} ArrayOperator;
typedef struct ModOperator
{
TypeOfOperator type;
LeafValue *divisor;
LeafValue *remainder;
} ModOperator;
typedef struct Operator
{
TypeOfOperator type;
} Operator;
typedef struct OperatorObject
{
List *operatorList;
} OperatorObject;
typedef struct MValue
{
TypeOfValue type;
union
{
LeafValue *lv;
OperatorObject *oob;
};
} MValue;
typedef struct LeafClause
{
TypeOfClause type;
char *key;
MValue *vl;
} LeafClause;
typedef struct CommentClause
{
TypeOfClause type;
char *op;
char *str;
} CommentClause;
typedef struct WhereClauseValue
{
TypeOfClause type;
TypeOfWhereClauseValue val_type;
char *str;
} WhereClauseValue;
typedef struct WhereClause
{
TypeOfClause type;
WhereClauseValue *wcv;
} WhereClause;
typedef struct TextClause
{
TypeOfClause type;
char *search_str;
bool lang_op;
char *lang_str;
bool case_sense;
bool diacr_sense;
} TextClause;
typedef struct Clause
{
TypeOfClause type;
} Clause;
typedef struct Expression
{
List *clauseList;
} Expression;
typedef struct ElemMatchOperator
{
TypeOfOperator type;
TypeOfElemMatchValue typeOfValue;
union
{
Expression *expression;
OperatorObject *operatorOpbject;
};
} ElemMatchOperator;
typedef struct ExpressionClause
{
TypeOfClause type;
ExpressionOperatorType op;
List *expressionList;
} ExpressionClause;
typedef struct MQuery
{
Expression *exp;
Datum jsQuery;
} MQuery;
extern MArray *createNewArray(List *arrayList);
extern List *addArrayElement(LeafValue * value, List *arrayList);
extern Operator *createNotOperator(Operator *op);
extern Operator *createModOperator(LeafValue *divisor, LeafValue *remainder);
extern Operator *createArrayOperator(ArrayOperatorType op, MArray *ar);
extern Operator *createValueOperator(ValueOperatorType op, LeafValue *value);
extern Operator *createElemMatchOperatorExpression(Expression *expression);
extern Operator *createElemMatchOperatorOpObject(OperatorObject *oob);
extern LeafValue *createStringValue(char *str);
extern LeafValue *createDoubleValue(char* d);
extern LeafValue *createIntegerValue(char* i);
extern LeafValue *createArrayValue(MArray *ar);
extern LeafValue *createBooleanValue(bool b);
extern List *addOperator(Operator *op, List *operatorList);
extern OperatorObject *createOperatorObject(List *operatorList);
extern MValue *createOperatorObjectValue(OperatorObject *oob);
extern MValue *createLeafValueValue(LeafValue *lv);
extern Clause *createLeafClause(char* key, MValue *vl);
extern Clause *createCommentClause(char *op, char *str);
extern WhereClauseValue *stringToWhereClauseValue(char *str);
extern Clause *createWhereClause(WhereClauseValue *wcv);
extern List *addClause(Clause *clause, List *clauseList);
extern Expression *createExpression(List *clauseList);
extern List *addExpression(Expression *exp, List *expressionList);
extern Clause *createExpressionTreeClause(ExpressionOperatorType op, List *expressionList);
extern Clause *createTextClause(char* search_str, bool lang_op, char* lang_str, bool case_sense, bool diacr_sense);
extern MQuery *createQuery(Expression *exp);
extern void deleteMquery(MQuery *qu);
#endif