PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ parse_values()

static void parse_values ( mvt_agg_context ctx)
static

Definition at line 565 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(), mvt_agg_context::row, and UINT32_MAX.

Referenced by mvt_agg_transfn().

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