forked from pramsey/pgsql-ogr-fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogr_fdw.h
203 lines (180 loc) · 5.21 KB
/
ogr_fdw.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
/*-------------------------------------------------------------------------
*
* ogr_fdw.h
* foreign-data wrapper for GIS data access.
*
* Copyright (c) 2014-2015, Paul Ramsey <[email protected]>
*
*-------------------------------------------------------------------------
*/
#ifndef _OGR_FDW_H
#define _OGR_FDW_H 1
#define OGR_FDW_RELEASE_NAME "1.1"
/*
* PostgreSQL
*/
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/reloptions.h"
#include "access/sysattr.h"
#include "access/transam.h"
#include "catalog/namespace.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_foreign_table.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "commands/copy.h"
#include "commands/defrem.h"
#include "commands/explain.h"
#include "commands/vacuum.h"
#include "foreign/fdwapi.h"
#include "foreign/foreign.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/planmain.h"
#include "optimizer/restrictinfo.h"
#include "parser/parsetree.h"
#include "storage/ipc.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/rel.h"
#include "utils/syscache.h"
#include "utils/timestamp.h"
#if PG_VERSION_NUM < 120000
#include "nodes/relation.h"
#include "optimizer/var.h"
#else
#include "executor/tuptable.h"
#endif
/* GDAL/OGR includes and compat */
#include "ogr_fdw_gdal.h"
#include "ogr_fdw_common.h"
/* Local configuration defines */
/* Use hexwkb input by default, but have option to use */
/* the binary recv input instead. Binary input is strict */
/* on geometry structure (no unclosed polys, etc) and */
/* hexwkb is not. */
#define OGR_FDW_HEXWKB TRUE
typedef enum
{
OGR_UNMATCHED,
OGR_GEOMETRY,
OGR_FID,
OGR_FIELD
} OgrColumnVariant;
typedef enum {
OGR_UPDATEABLE_FALSE,
OGR_UPDATEABLE_TRUE,
OGR_UPDATEABLE_UNSET,
OGR_UPDATEABLE_TRY
} OgrUpdateable;
typedef struct OgrFdwColumn
{
/* PgSQL metadata */
int pgattnum; /* PostgreSQL attribute number */
int pgattisdropped; /* PostgreSQL attribute dropped? */
char* pgname; /* PostgreSQL column name */
Oid pgtype; /* PostgreSQL data type */
int pgtypmod; /* PostgreSQL type modifier */
/* For reading */
Oid pginputfunc; /* PostgreSQL function to convert cstring to type */
Oid pginputioparam;
Oid pgrecvfunc; /* PostgreSQL function to convert binary to type */
Oid pgrecvioparam;
/* For writing */
Oid pgoutputfunc; /* PostgreSQL function to convert type to cstring */
bool pgoutputvarlena;
Oid pgsendfunc; /* PostgreSQL function to convert type to binary */
bool pgsendvarlena;
/* OGR metadata */
OgrColumnVariant ogrvariant;
int ogrfldnum;
OGRFieldType ogrfldtype;
} OgrFdwColumn;
typedef struct OgrFdwTable
{
int ncols;
char* tblname;
OgrFdwColumn* cols;
} OgrFdwTable;
typedef struct OgrFdwSpatialFilter
{
int ogrfldnum;
double minx, miny, maxx, maxy;
} OgrFdwSpatialFilter;
typedef struct OgrConnection
{
const char* ds_str; /* datasource connection string */
const char* dr_str; /* driver (format) name */
char* lyr_str; /* layer name */
const char* config_options; /* GDAL config options */
const char* open_options; /* GDAL open options */
OgrUpdateable ds_updateable;
OgrUpdateable lyr_updateable;
int char_encoding; /* Is OGR layer UTF? Has user provided encoding open option? */
GDALDatasetH ds; /* GDAL datasource handle */
OGRLayerH lyr; /* OGR layer handle */
} OgrConnection;
typedef enum
{
OGR_PLAN_STATE,
OGR_EXEC_STATE,
OGR_MODIFY_STATE
} OgrFdwStateType;
typedef struct OgrFdwState
{
OgrFdwStateType type;
Oid foreigntableid;
OgrConnection ogr; /* connection object */
OgrFdwTable* table;
TupleDesc tupdesc;
} OgrFdwState;
typedef struct OgrFdwPlanState
{
OgrFdwStateType type;
Oid foreigntableid;
OgrConnection ogr;
OgrFdwTable* table;
TupleDesc tupdesc;
int nrows; /* estimate of number of rows in file */
Cost startup_cost;
Cost total_cost;
bool* pushdown_clauses;
} OgrFdwPlanState;
typedef struct OgrFdwExecState
{
OgrFdwStateType type;
Oid foreigntableid;
OgrConnection ogr;
OgrFdwTable *table;
TupleDesc tupdesc;
char* sql; /* OGR SQL for attribute filter */
int rownum; /* how many rows have we read thus far? */
Oid setsridfunc; /* ST_SetSRID() */
Oid typmodsridfunc; /* postgis_typmod_srid() */
} OgrFdwExecState;
typedef struct OgrFdwModifyState
{
OgrFdwStateType type;
Oid foreigntableid;
OgrConnection ogr; /* connection object */
OgrFdwTable* table;
TupleDesc tupdesc;
} OgrFdwModifyState;
/* Shared function signatures */
bool ogrDeparse(StringInfo buf, PlannerInfo* root, RelOptInfo* foreignrel, List* exprs, OgrFdwState* state, List** params_list, OgrFdwSpatialFilter** sf);
Oid ogrGetGeometryOid(void);
OGRErr pgDatumToOgrGeometry (Datum pg_geometry, Oid pgsendfunc, OGRGeometryH* ogr_geometry);
#endif /* _OGR_FDW_H */