forked from EnterpriseDB/mongo_fdw
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeparse.c
85 lines (71 loc) · 1.95 KB
/
deparse.c
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
/*-------------------------------------------------------------------------
*
* deparse.c
* Query deparser for mongo_fdw
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 2004-2022, EnterpriseDB Corporation.
* Portions Copyright (c) 2012–2014 Citus Data, Inc.
* Portions Copyright (c) 2021, TOSHIBA CORPORATION
*
* IDENTIFICATION
* deparse.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "mongo_wrapper.h"
/*
* mongo_get_jointype_name
* Output join name for given join type
*/
const char *
mongo_get_jointype_name(JoinType jointype)
{
switch (jointype)
{
case JOIN_INNER:
return "INNER";
case JOIN_LEFT:
return "LEFT";
case JOIN_RIGHT:
return "RIGHT";
default:
/* Shouldn't come here, but protect from buggy code. */
elog(ERROR, "unsupported join type %d", jointype);
}
/* Keep compiler happy */
return NULL;
}
/*
* mongo_add_null_check_ref
* Add null check for reference
*/
void mongo_add_null_check_ref(char *ref_name, BSON *qdoc)
{
BSON ne_expr,ref_doc;
bsonAppendStartObject (qdoc, "$epxr", &ref_doc);
bsonAppendStartArray(&ref_doc, "$ne", &ne_expr);
bsonAppendUTF8(&ne_expr, "0", ref_name);
bsonAppendNull(&ne_expr, "1");
bsonAppendFinishArray(&ref_doc, &ne_expr);
bsonAppendFinishObject (qdoc, &ref_doc);
}
/*
* mongo_add_null_check_var
* Add null check for column
*/
void mongo_add_null_check_var(Var *node, BSON *qdoc, Oid rel_oid)
{
BSON ne_expr,ref_doc;
char *colname = NULL;
bsonAppendStartObject(qdoc, "$epxr", &ref_doc);
bsonAppendStartArray(&ref_doc, "$ne", &ne_expr);
colname = get_attname(rel_oid, node->varattno, false);
/* Build colname object like "$column" */
colname = psprintf("$%s", colname);
bsonAppendUTF8(&ne_expr, "0", colname);
bsonAppendNull(&ne_expr, "1");
bsonAppendFinishArray(&ref_doc, &ne_expr);
bsonAppendFinishObject (qdoc, &ref_doc);
}