[postgis-tickets] r15387 - ST_AsMVT JSONB support and regression tests conditional on PG >= 94

bjorn at wololo.org bjorn at wololo.org
Thu May 4 10:15:17 PDT 2017


Author: bjornharrtell
Date: 2017-05-04 10:15:16 -0700 (Thu, 04 May 2017)
New Revision: 15387

Added:
   trunk/regress/mvt_jsonb.sql
   trunk/regress/mvt_jsonb_expected
Modified:
   trunk/postgis/mvt.c
   trunk/postgis/mvt.h
   trunk/regress/Makefile.in
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
ST_AsMVT JSONB support and regression tests conditional on PG >= 94
Fixes #3749

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-05-04 05:07:46 UTC (rev 15386)
+++ trunk/postgis/mvt.c	2017-05-04 17:15:16 UTC (rev 15387)
@@ -26,6 +26,10 @@
 
 #ifdef HAVE_LIBPROTOBUF
 
+#if POSTGIS_PGSQL_VERSION >= 94
+#include "utils/jsonb.h"
+#endif
+
 #include "uthash.h"
 
 #define FEATURES_CAPACITY_INITIAL 50
@@ -301,8 +305,10 @@
 	bool geom_name_found = false;
 	for (i = 0; i < natts; i++) {
 		Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
+#if POSTGIS_PGSQL_VERSION >= 94
 		if (typoid == JSONBOID)
 			continue;
+#endif
 		char *tkey = tupdesc->attrs[i]->attname.data;
 		char *key = palloc(strlen(tkey) + 1);
 		strcpy(key, tkey);
@@ -462,6 +468,7 @@
 	add_value_as_string(ctx, value, tags, k);
 }
 
+#if POSTGIS_PGSQL_VERSION >= 94
 static uint32_t *parse_jsonb(struct mvt_agg_context *ctx, Jsonb *jb,
 	uint32_t *tags)
 {
@@ -524,6 +531,7 @@
 
 	return tags;
 }
+#endif
 
 static void parse_values(struct mvt_agg_context *ctx)
 {
@@ -546,17 +554,23 @@
 		Datum datum = GetAttributeByNum(ctx->row, i+1, &isnull);
 		Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
 		k = get_key_index(ctx, key);
-		if (k == -1 && typoid != JSONBOID)
-			lwerror("parse_values: unexpectedly could not find parsed key name",
-				key);
 		if (isnull) {
 			POSTGIS_DEBUG(3, "parse_values isnull detected");
 			continue;
 		}
+#if POSTGIS_PGSQL_VERSION >= 94
+		if (k == -1 && typoid != JSONBOID)
+#else
+		if (k == -1)
+#endif
+			lwerror("parse_values: unexpectedly could not find parsed key name",
+				key);
+#if POSTGIS_PGSQL_VERSION >= 94
 		if (typoid == JSONBOID) {
 			tags = parse_jsonb(ctx, DatumGetJsonb(datum), tags);
 			continue;
 		}
+#endif
 		switch (typoid) {
 		case BOOLOID:
 			MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,

Modified: trunk/postgis/mvt.h
===================================================================
--- trunk/postgis/mvt.h	2017-05-04 05:07:46 UTC (rev 15386)
+++ trunk/postgis/mvt.h	2017-05-04 17:15:16 UTC (rev 15387)
@@ -31,7 +31,6 @@
 #include "utils/array.h"
 #include "utils/typcache.h"
 #include "utils/lsyscache.h"
-#include "utils/jsonb.h"
 #include "catalog/pg_type.h"
 #include "executor/executor.h"
 #include "access/htup_details.h"
@@ -65,7 +64,7 @@
 	uint32_t values_hash_i;
 	uint32_t keys_hash_i;
 	uint32_t c;
-} ;
+};
 
 LWGEOM *mvt_geom(LWGEOM *geom, GBOX *bounds, uint32_t extent, uint32_t buffer,
 	bool clip_geom);

Modified: trunk/regress/Makefile.in
===================================================================
--- trunk/regress/Makefile.in	2017-05-04 05:07:46 UTC (rev 15386)
+++ trunk/regress/Makefile.in	2017-05-04 17:15:16 UTC (rev 15387)
@@ -247,7 +247,11 @@
 	TESTS += \
 		mvt \
 		geobuf
+ifeq ($(shell expr $(POSTGIS_PGSQL_VERSION) ">=" 94),1)
+	TESTS += \
+		mvt_jsonb
 endif
+endif
 
 ifeq ($(HAVE_SFCGAL),yes)
 	# SFCGAL additionnal backend

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2017-05-04 05:07:46 UTC (rev 15386)
+++ trunk/regress/mvt.sql	2017-05-04 17:15:16 UTC (rev 15387)
@@ -109,12 +109,6 @@
     UNION
     SELECT 2::int AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(26 18)'),
     ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;
-SELECT 'TA9', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":1,"c2":"abcd"}'::jsonb,
-    ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
-    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;
-SELECT 'TA10', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":"abcd", "c2":"abcd"}'::jsonb,
-    ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
-    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;
 
 -- unsupported input
 SELECT 'TU2';

Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected	2017-05-04 05:07:46 UTC (rev 15386)
+++ trunk/regress/mvt_expected	2017-05-04 17:15:16 UTC (rev 15387)
@@ -28,8 +28,6 @@
 CW90aGVydGVzdCIGCgR0ZXN0KIAgeAI=
 TA8|GkEKBHRlc3QSDBICAAAYASIECTLePxIMEgIAABgBIgQJNNw/EgwSAgABGAEiBAk03D8aAmMxIgIo
 ASICKAIogCB4Ag==
-TA9|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag==
-TA10|GisKBHRlc3QSDhIEAAABABgBIgQJMt4/GgJjMRoCYzIiBgoEYWJjZCiAIHgC
 TU2
 ERROR:  pgis_asmvt_transfn: parameter row cannot be other than a rowtype
 TU3

Added: trunk/regress/mvt_jsonb.sql
===================================================================
--- trunk/regress/mvt_jsonb.sql	                        (rev 0)
+++ trunk/regress/mvt_jsonb.sql	2017-05-04 17:15:16 UTC (rev 15387)
@@ -0,0 +1,6 @@
+SELECT 'TA9', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":1,"c2":"abcd"}'::jsonb,
+    ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
+    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;
+SELECT 'TA10', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT '{"c1":"abcd", "c2":"abcd"}'::jsonb,
+    ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),
+    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q;

Added: trunk/regress/mvt_jsonb_expected
===================================================================
--- trunk/regress/mvt_jsonb_expected	                        (rev 0)
+++ trunk/regress/mvt_jsonb_expected	2017-05-04 17:15:16 UTC (rev 15387)
@@ -0,0 +1,2 @@
+TA9|Gi8KBHRlc3QSDhIEAAABARgBIgQJMt4/GgJjMRoCYzIiAigBIgYKBGFiY2QogCB4Ag==
+TA10|GisKBHRlc3QSDhIEAAABABgBIgQJMt4/GgJjMRoCYzIiBgoEYWJjZCiAIHgC



More information about the postgis-tickets mailing list