PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ parse_values()

static void parse_values ( struct mvt_agg_context ctx)
static

Definition at line 556 of file mvt.c.

References mvt_agg_context::c, DatumGetJsonbP, mvt_agg_context::feature, mvt_agg_context::geom_index, get_key_index(), get_tuple_desc(), mvt_agg_context::keys_hash_i, MVT_PARSE_DATUM, MVT_PARSE_INT_DATUM, parse_datum_as_string(), parse_jsonb(), and mvt_agg_context::row.

Referenced by mvt_agg_transfn().

557 {
558  POSTGIS_DEBUG(2, "parse_values called");
559  uint32_t n_keys = ctx->keys_hash_i;
560  uint32_t *tags = palloc(n_keys * 2 * sizeof(*tags));
561  bool isnull;
562  uint32_t i, k;
563  TupleDesc tupdesc = get_tuple_desc(ctx);
564  int natts = tupdesc->natts;
565  ctx->c = 0;
566 
567  POSTGIS_DEBUGF(3, "parse_values natts: %d", natts);
568 
569  for (i = 0; i < natts; i++) {
570  char *key;
571  Oid typoid;
572  Datum datum;
573 
574  if (i == ctx->geom_index)
575  continue;
576 
577 #if POSTGIS_PGSQL_VERSION < 110
578  key = tupdesc->attrs[i]->attname.data;
579  typoid = getBaseType(tupdesc->attrs[i]->atttypid);
580 #else
581  key = tupdesc->attrs[i].attname.data;
582  typoid = getBaseType(tupdesc->attrs[i].atttypid);
583 #endif
584  datum = GetAttributeByNum(ctx->row, i+1, &isnull);
585  k = get_key_index(ctx, key);
586  if (isnull) {
587  POSTGIS_DEBUG(3, "parse_values isnull detected");
588  continue;
589  }
590 #if POSTGIS_PGSQL_VERSION >= 94
591  if (k == -1 && typoid != JSONBOID)
592  elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
593  if (typoid == JSONBOID) {
594  tags = parse_jsonb(ctx, DatumGetJsonbP(datum), tags);
595  continue;
596  }
597 #else
598  if (k == -1)
599  elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
600 #endif
601 
602  switch (typoid) {
603  case BOOLOID:
604  MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,
605  bool_values_hash, bool_value,
606  DatumGetBool, sizeof(protobuf_c_boolean));
607  break;
608  case INT2OID:
609  MVT_PARSE_INT_DATUM(int16_t, DatumGetInt16);
610  break;
611  case INT4OID:
612  MVT_PARSE_INT_DATUM(int32_t, DatumGetInt32);
613  break;
614  case INT8OID:
615  MVT_PARSE_INT_DATUM(int64_t, DatumGetInt64);
616  break;
617  case FLOAT4OID:
619  float_values_hash, float_value,
620  DatumGetFloat4, sizeof(float));
621  break;
622  case FLOAT8OID:
624  double_values_hash, double_value,
625  DatumGetFloat8, sizeof(double));
626  break;
627  default:
628  parse_datum_as_string(ctx, typoid, datum, tags, k);
629  break;
630  }
631  ctx->c++;
632  }
633 
634  ReleaseTupleDesc(tupdesc);
635 
636  ctx->feature->n_tags = ctx->c * 2;
637  ctx->feature->tags = tags;
638 
639  POSTGIS_DEBUGF(3, "parse_values n_tags %zd", ctx->feature->n_tags);
640 }
HeapTupleHeader row
Definition: mvt.h:54
uint32_t c
Definition: mvt.h:67
static TupleDesc get_tuple_desc(struct mvt_agg_context *ctx)
Definition: mvt.c:275
static uint32_t * parse_jsonb(struct mvt_agg_context *ctx, Jsonb *jb, uint32_t *tags)
Definition: mvt.c:492
static void parse_datum_as_string(struct mvt_agg_context *ctx, Oid typoid, Datum datum, uint32_t *tags, uint32_t k)
Definition: mvt.c:478
unsigned int uint32_t
Definition: uthash.h:78
uint32_t keys_hash_i
Definition: mvt.h:66
static uint32_t get_key_index(struct mvt_agg_context *ctx, char *name)
Definition: mvt.c:283
uint32_t geom_index
Definition: mvt.h:53
VectorTile__Tile__Feature * feature
Definition: mvt.h:55
#define MVT_PARSE_DATUM(type, kvtype, hash, valuefield, datumfunc, size)
Definition: mvt.c:445
#define DatumGetJsonbP
Definition: mvt.c:35
#define MVT_PARSE_INT_DATUM(type, datumfunc)
Definition: mvt.c:451
Here is the call graph for this function:
Here is the caller graph for this function: