forked from citusdata/mongo_fdw
-
Notifications
You must be signed in to change notification settings - Fork 70
/
mongo_query.h
150 lines (127 loc) · 4.45 KB
/
mongo_query.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
/*-------------------------------------------------------------------------
*
* mongo_query.h
* FDW query handling for mongo_fdw
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 2004-2024, EnterpriseDB Corporation.
* Portions Copyright (c) 2012–2014 Citus Data, Inc.
*
* IDENTIFICATION
* mongo_query.h
*
*-------------------------------------------------------------------------
*/
#ifndef MONGO_QUERY_H
#define MONGO_QUERY_H
#define NUMERICARRAY_OID 1231
/*
* Context for aggregation pipeline formation.
*/
typedef struct pipeline_cxt
{
struct HTAB *colInfoHash; /* columns information hash */
unsigned int arrayIndex; /* Index of the various arrays in the
* pipeline, starting from zero */
bool isBoolExpr; /* is join expression boolean? */
bool isJoinClause; /* is join clause? This is to add null check
* only in case of join clause */
uint32 opExprCount; /* count death of the expression */
ForeignScanState *scanStateNode; /* To evaluate param expression */
} pipeline_cxt;
/*
* ColInfoEntry represents a hash table entry that maps a unique column's varno
* and varattno to the column name and related information. We construct these
* hash table entries to speed up the BSON query document formation.
*/
typedef struct ColInfoHashKey
{
int varNo;
int varAttno;
} ColInfoHashKey;
typedef struct ColInfoEntry
{
ColInfoHashKey key; /* Hash key */
char *colName;
bool isOuter;
} ColInfoHashEntry;
/*
* Indexes of FDW-private information stored in fdw_private lists.
*
* These items are indexed with the enum mongoFdwScanPrivateIndex, so an item
* can be fetched with list_nth(). For example, to get the column list:
* col_list = strVal(list_nth(fdw_private, mongoFdwPrivateColumnList));
*/
enum mongoFdwScanPrivateIndex
{
/*
* Column list to form column mapping hash i.e. to get only needed columns
* from all fetched columns from remote.
*/
mongoFdwPrivateColumnList,
/* Expressions to execute remotely */
mongoFdwPrivateRemoteExprList,
/* Relation Type (BASE/JOIN/UPPER/UPPER_JOIN) */
mongoFdwPrivateRelType,
/*
* List of column name, attribute number, range table index, and whether
* this column is of outer relation or not.
*
* The columns which are part of the join clauses are listed.
*/
mongoFdwPrivateJoinClauseColNameList,
mongoFdwPrivareJoinClauseColNumList,
mongoFdwPrivateJoinClauseRtiList,
mongoFdwPrivateJoinClauseIsOuterList,
/* ORDER BY clause information */
mongoFdwPrivatePathKeyList,
mongoFdwPrivateIsAscSortList,
/* LIMIT/OFFSET clause information */
mongoFdwPrivateHasLimitClause,
mongoFdwPrivateLimitCountList,
mongoFdwPrivateLimitOffsetList,
/* Upper relation information */
/* Upper relation grouping operation name list */
mongoFdwPrivateAggType,
/* List of column names involved in grouping operation list */
mongoFdwPrivateAggColList,
/* GROUP BY clause expression */
mongoFdwPrivateGroupByColList,
/* Having expression */
mongoFdwPrivateHavingExpr,
/* Is the grouping expression part of HAVING expression or not? */
mongoFdwPrivateIsHavingList,
/*
* String describing join i.e. names of relations being joined and types
* of join, added when the scan is join
*/
mongoFdwPrivateRelations,
/*
* List of column names and whether those are part of inner or outer
* relation stored to form Column Mapping Hash. These are needed column
* means those are part of target and restriction columns.
*/
mongoFdwPrivateColNameList,
mongoFdwPrivateColIsInnerList,
/* Inner and Outer relation names */
mongoFdwPrivateJoinInnerOuterRelName,
/* List of join clauses to form a pipeline */
mongoFdwPrivateJoinClauseList,
/* Join-type */
mongoFdwPrivateJoinType
};
/* Function to be used in mongo_fdw.c */
extern bool append_mongo_value(BSON *queryDocument, const char *keyName,
Datum value, bool isnull, Oid id);
/* Functions to be used in deparse.c */
extern char *mongo_operator_name(const char *operatorName);
extern void append_constant_value(BSON *queryDocument, const char *keyName,
Const *constant);
extern void mongo_append_expr(Expr *node, BSON *child_doc,
pipeline_cxt *context);
extern void append_param_value(BSON *queryDocument, const char *keyName,
Param *paramNode,
ForeignScanState *scanStateNode);
extern char *get_varname_for_outer_col(const char *str);
extern void mongo_replace_char(char* str, char find, char replace);
#endif /* MONGO_QUERY_H */