-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgo_fdw.c
128 lines (114 loc) · 3.51 KB
/
go_fdw.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
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
/*-------------------------------------------------------------------------
*
* go_fdw.c
* HelloWorld of foreign-data wrapper.
*
* written by Wataru Ikarashi <[email protected]>
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/planmain.h"
#include "utils/palloc.h"
#include <sys/stat.h>
#include <unistd.h>
#include "go_fdw.h"
PG_MODULE_MAGIC;
extern Datum go_fdw_handler(PG_FUNCTION_ARGS);
extern Datum go_fdw_validator(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(go_fdw_handler);
PG_FUNCTION_INFO_V1(go_fdw_validator);
/*
* FDW callback routines
*/
static ForeignScan *goGetForeignPlan(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
List *scan_clauses,
Plan *outer_plan);
//static TupleTableSlot *goIterateForeignScan(ForeignScanState *node);
Datum
go_fdw_handler(PG_FUNCTION_ARGS)
{
FdwRoutine *fdwroutine = makeNode(FdwRoutine);
fdwroutine->GetForeignRelSize = goGetForeignRelSize;
fdwroutine->GetForeignPaths = goGetForeignPaths;
fdwroutine->GetForeignPlan = goGetForeignPlan;
fdwroutine->ExplainForeignScan = goExplainForeignScan;
fdwroutine->BeginForeignScan = goBeginForeignScan;
fdwroutine->IterateForeignScan = goIterateForeignScan;
fdwroutine->ReScanForeignScan = goReScanForeignScan;
fdwroutine->EndForeignScan = goEndForeignScan;
fdwroutine->AnalyzeForeignTable = goAnalyzeForeignTable;
PG_RETURN_POINTER(fdwroutine);
}
Datum
go_fdw_validator(PG_FUNCTION_ARGS)
{
/* no-op */
PG_RETURN_VOID();
}
/*
* goGetForeignPlan
* Create a ForeignScan plan node for scanning the foreign table
*/
static ForeignScan *
goGetForeignPlan(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
List *scan_clauses,
Plan *outer_plan)
{
scan_clauses = extract_actual_clauses(scan_clauses, false);
return make_foreignscan(tlist,
scan_clauses,
baserel->relid,
NIL,
best_path->fdw_private,
NIL, /* no custom tlist */
NIL, /* no remote quals */
outer_plan);
}
/*
* goIterateForeignScan
* Generate next record and store it into the ScanTupleSlot as a virtual tuple
*/
//static TupleTableSlot *
//goIterateForeignScan(ForeignScanState *node)
//{
// TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
// Relation rel;
// AttInMetadata *attinmeta;
// HeapTuple tuple;
// GoFdwExecutionState *hestate = (GoFdwExecutionState *) node->fdw_state;
// int i;
// int natts;
// char **values;
//
// if( hestate->rownum != 0 ){
// ExecClearTuple(slot);
// return slot;
// }
//
// rel = node->ss.ss_currentRelation;
// attinmeta = TupleDescGetAttInMetadata(rel->rd_att);
//
// natts = rel->rd_att->natts;
// values = (char **) palloc(sizeof(char *) * natts);
//
// for(i = 0; i < natts; i++ ){
// values[i] = "Hello,World";
// }
//
// tuple = BuildTupleFromCStrings(attinmeta, values);
// ExecStoreTuple(tuple, slot, InvalidBuffer, true);
//
// hestate->rownum++;
//
// return slot;
//}