forked from pgspider/parquet_s3_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parquet_fdw.c
204 lines (187 loc) · 6.75 KB
/
parquet_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
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
/*-------------------------------------------------------------------------
*
* parquet_fdw.c
* FDW routines for parquet_s3_fdw
*
* Portions Copyright (c) 2020, TOSHIBA CORPORATION
* Portions Copyright (c) 2018-2019, adjust GmbH
*
* IDENTIFICATION
* contrib/parquet_s3_fdw/src/parquet_fdw.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "fmgr.h"
#include "access/reloptions.h"
#include "catalog/pg_foreign_table.h"
#include "commands/defrem.h"
#include "commands/explain.h"
#include "foreign/fdwapi.h"
#include "storage/ipc.h"
#include "optimizer/planmain.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/elog.h"
#include "nodes/execnodes.h"
#include "parquet_s3_fdw.h"
PG_MODULE_MAGIC;
void _PG_init(void);
extern void parquet_s3_init();
extern void parquet_s3_shutdown();
/* FDW routines */
extern void parquetGetForeignRelSize(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid);
extern void parquetGetForeignPaths(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid);
extern ForeignScan *parquetGetForeignPlan(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
List *scan_clauses,
Plan *outer_plan);
extern TupleTableSlot *parquetIterateForeignScan(ForeignScanState *node);
extern void parquetBeginForeignScan(ForeignScanState *node, int eflags);
extern void parquetEndForeignScan(ForeignScanState *node);
extern void parquetReScanForeignScan(ForeignScanState *node);
extern void parquetAddForeignUpdateTargets(
#if (PG_VERSION_NUM >= 140000)
PlannerInfo *root,
Index rtindex,
#else
Query *parsetree,
#endif
RangeTblEntry *target_rte,
Relation target_relation);
extern List* parquetPlanForeignModify(PlannerInfo *root,
ModifyTable *plan,
Index resultRelation,
int subplan_index);
extern void parquetBeginForeignModify(ModifyTableState *mtstate,
ResultRelInfo *resultRelInfo,
List *fdw_private,
int subplan_index,
int eflags);
extern void parquetEndForeignModify(EState *estate,
ResultRelInfo *resultRelInfo);
extern TupleTableSlot *parquetExecForeignUpdate(EState *estate,
ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
TupleTableSlot *planSlot);
extern TupleTableSlot *parquetExecForeignInsert(EState *estate,
ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
TupleTableSlot *planSlot);
extern TupleTableSlot *parquetExecForeignDelete(EState *estate,
ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
TupleTableSlot *planSlot);
extern int parquetAcquireSampleRowsFunc(Relation relation, int elevel,
HeapTuple *rows, int targrows,
double *totalrows,
double *totaldeadrows);
extern bool parquetAnalyzeForeignTable(Relation relation,
AcquireSampleRowsFunc *func,
BlockNumber *totalpages);
extern void parquetExplainForeignScan(ForeignScanState *node, ExplainState *es);
extern bool parquetIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
RangeTblEntry *rte);
extern Size parquetEstimateDSMForeignScan(ForeignScanState *node,
ParallelContext *pcxt);
extern void parquetInitializeDSMForeignScan(ForeignScanState *node,
ParallelContext *pcxt,
void *coordinate);
extern void parquetReInitializeDSMForeignScan(ForeignScanState *node,
ParallelContext *pcxt,
void *coordinate);
extern void parquetInitializeWorkerForeignScan(ForeignScanState *node,
shm_toc *toc,
void *coordinate);
extern void parquetShutdownForeignScan(ForeignScanState *node);
extern List *parquetImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid);
extern Datum parquet_fdw_validator_impl(PG_FUNCTION_ARGS);
/* GUC variable */
extern bool parquet_fdw_use_threads;
extern bool enable_multifile;
extern bool enable_multifile_merge;
void
_PG_init(void)
{
DefineCustomBoolVariable("parquet_s3_fdw.use_threads",
"Enables use_thread option",
NULL,
&parquet_fdw_use_threads,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
parquet_s3_init();
on_proc_exit(&parquet_s3_shutdown, PointerGetDatum(NULL));
DefineCustomBoolVariable("parquet_fdw.enable_multifile",
"Enables Multifile reader",
NULL,
&enable_multifile,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
DefineCustomBoolVariable("parquet_fdw.enable_multifile_merge",
"Enables Multifile Merge reader",
NULL,
&enable_multifile_merge,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);
}
PG_FUNCTION_INFO_V1(parquet_s3_fdw_validator);
PG_FUNCTION_INFO_V1(parquet_s3_fdw_version);
Datum
parquet_s3_fdw_version(PG_FUNCTION_ARGS)
{
PG_RETURN_INT32(CODE_VERSION);
}
Datum
parquet_s3_fdw_validator(PG_FUNCTION_ARGS)
{
return parquet_fdw_validator_impl(fcinfo);
}
PG_FUNCTION_INFO_V1(parquet_s3_fdw_handler);
Datum
parquet_s3_fdw_handler(PG_FUNCTION_ARGS)
{
FdwRoutine *fdwroutine = makeNode(FdwRoutine);
fdwroutine->GetForeignRelSize = parquetGetForeignRelSize;
fdwroutine->GetForeignPaths = parquetGetForeignPaths;
fdwroutine->GetForeignPlan = parquetGetForeignPlan;
fdwroutine->BeginForeignScan = parquetBeginForeignScan;
fdwroutine->IterateForeignScan = parquetIterateForeignScan;
fdwroutine->ReScanForeignScan = parquetReScanForeignScan;
fdwroutine->EndForeignScan = parquetEndForeignScan;
fdwroutine->AnalyzeForeignTable = parquetAnalyzeForeignTable;
fdwroutine->ExplainForeignScan = parquetExplainForeignScan;
fdwroutine->IsForeignScanParallelSafe = parquetIsForeignScanParallelSafe;
fdwroutine->EstimateDSMForeignScan = parquetEstimateDSMForeignScan;
fdwroutine->InitializeDSMForeignScan = parquetInitializeDSMForeignScan;
fdwroutine->ReInitializeDSMForeignScan = parquetReInitializeDSMForeignScan;
fdwroutine->InitializeWorkerForeignScan = parquetInitializeWorkerForeignScan;
fdwroutine->ShutdownForeignScan = parquetShutdownForeignScan;
fdwroutine->ImportForeignSchema = parquetImportForeignSchema;
fdwroutine->AddForeignUpdateTargets = parquetAddForeignUpdateTargets;
fdwroutine->PlanForeignModify = parquetPlanForeignModify;
fdwroutine->BeginForeignModify = parquetBeginForeignModify;
fdwroutine->ExecForeignUpdate = parquetExecForeignUpdate;
fdwroutine->ExecForeignInsert = parquetExecForeignInsert;
fdwroutine->ExecForeignDelete = parquetExecForeignDelete;
fdwroutine->EndForeignModify = parquetEndForeignModify;
PG_RETURN_POINTER(fdwroutine);
}