Skip to content

Commit c719d3f

Browse files
jpechanegunnarmorling
authored andcommitted
DBZ-1144 Do not translate geometry point (PostGIS) to PG point
This code was effectivelly dead. It was used only when PostGIS geometry type was created inside the public schema and was responsible for translating of PostGIS point to PG point. When we introduced the full support for PostGIS types in Debezium the code was no longer used as PostGIS types are typically created in separate schema. So now we support * POINT type (postgres point) * postgis GEOMETRY in arbitrary schema (including geometry point)
1 parent 2a60a18 commit c719d3f

File tree

1 file changed

+1
-69
lines changed

1 file changed

+1
-69
lines changed

src/decoderbufs.c

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
#error Expecting timestamps to be represented as integers, not as floating-point.
6161
#endif
6262

63-
#ifdef USE_POSTGIS
64-
/* POSTGIS version define so it doesn't redef macros */
65-
#define POSTGIS_PGSQL_VERSION 94
66-
#include "liblwgeom.h"
67-
#endif
68-
6963
PG_MODULE_MAGIC;
7064

7165
/* define a time macro to convert TimestampTz into something more sane,
@@ -80,10 +74,6 @@ typedef struct {
8074
bool debug_mode;
8175
} DecoderData;
8276

83-
/* GLOBALs for PostGIS dynamic OIDs */
84-
Oid geometry_oid = InvalidOid;
85-
Oid geography_oid = InvalidOid;
86-
8777
/* these must be available to pg_dlsym() */
8878
extern void _PG_init(void);
8979
extern void _PG_output_plugin_init(OutputPluginCallbacks *cb);
@@ -177,22 +167,6 @@ static void pg_decode_shutdown(LogicalDecodingContext *ctx) {
177167
/* BEGIN callback */
178168
static void pg_decode_begin_txn(LogicalDecodingContext *ctx,
179169
ReorderBufferTXN *txn) {
180-
#ifdef USE_POSTGIS
181-
// set PostGIS geometry type id (these are dynamic)
182-
// TODO: Figure out how to make sure we get the typid's from postgis extension namespace
183-
if (geometry_oid == InvalidOid) {
184-
geometry_oid = TypenameGetTypid("geometry");
185-
if (geometry_oid != InvalidOid) {
186-
elog(DEBUG1, "PostGIS geometry type detected: %u", geometry_oid);
187-
}
188-
}
189-
if (geography_oid == InvalidOid) {
190-
geography_oid = TypenameGetTypid("geography");
191-
if (geography_oid != InvalidOid) {
192-
elog(DEBUG1, "PostGIS geometry type detected: %u", geography_oid);
193-
}
194-
}
195-
#endif
196170
}
197171

198172
/* COMMIT callback */
@@ -280,42 +254,6 @@ static void print_row_msg(StringInfo out, Decoderbufs__RowMessage *rmsg) {
280254

281255
}
282256

283-
static bool geography_point_as_decoderbufs_point(Datum datum,
284-
Decoderbufs__Point *p) {
285-
#ifdef USE_POSTGIS
286-
GSERIALIZED *geom;
287-
LWGEOM *lwgeom;
288-
LWPOINT *point = NULL;
289-
POINT2D p2d;
290-
291-
geom = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
292-
if (gserialized_get_type(geom) != POINTTYPE) {
293-
return false;
294-
}
295-
296-
lwgeom = lwgeom_from_gserialized(geom);
297-
point = lwgeom_as_lwpoint(lwgeom);
298-
if (lwgeom_is_empty(lwgeom)) {
299-
return false;
300-
}
301-
302-
getPoint2d_p(point->point, 0, &p2d);
303-
304-
if (p != NULL) {
305-
Decoderbufs__Point dp = DECODERBUFS__POINT__INIT;
306-
dp.x = p2d.x;
307-
dp.y = p2d.y;
308-
memcpy(p, &dp, sizeof(dp));
309-
elog(DEBUG1, "Translating geography to point: (x,y) = (%f,%f)", p->x, p->y);
310-
}
311-
312-
return true;
313-
#else
314-
elog(DEBUG1, "PostGIS support is off, recompile decoderbufs with USE_POSTGIS option!");
315-
return false;
316-
#endif
317-
}
318-
319257
/* set a datum value based on its OID specified by typid */
320258
static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
321259
Oid typoutput, Datum datum) {
@@ -435,13 +373,7 @@ static void set_datum_value(Decoderbufs__DatumMessage *datum_msg, Oid typid,
435373
datum_msg->datum_case = DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_POINT;
436374
break;
437375
default:
438-
// PostGIS uses dynamic OIDs so we need to check the type again here
439-
if (typid == geometry_oid || typid == geography_oid) {
440-
elog(DEBUG1, "Converting geography point to datum_point");
441-
datum_msg->datum_point = palloc(sizeof(Decoderbufs__Point));
442-
geography_point_as_decoderbufs_point(datum, datum_msg->datum_point);
443-
datum_msg->datum_case = DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_POINT;
444-
} else {
376+
{
445377
int len;
446378
elog(DEBUG1, "Encountered unknown typid: %d, using bytes", typid);
447379
output = OidOutputFunctionCall(typoutput, datum);

0 commit comments

Comments
 (0)