PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ parse_values()

static void parse_values ( mvt_agg_context ctx)
static

Definition at line 629 of file mvt.c.

References mvt_agg_context::column_cache, mvt_column_cache::column_keys_index, mvt_column_cache::column_oid, DatumGetJsonbP, mvt_agg_context::feature, mvt_agg_context::geom_index, mvt_agg_context::keys_hash_i, MVT_PARSE_DATUM, MVT_PARSE_INT_DATUM, mvt_column_cache::nulls, parse_datum_as_string(), parse_jsonb(), mvt_agg_context::row, mvt_agg_context::row_columns, mvt_column_cache::tupdesc, UINT32_MAX, and mvt_column_cache::values.

Referenced by mvt_agg_transfn().

630 {
631  uint32_t n_keys = ctx->keys_hash_i;
632  uint32_t *tags = palloc(n_keys * 2 * sizeof(*tags));
633  uint32_t i;
634  mvt_column_cache cc = ctx->column_cache;
635  uint32_t natts = (uint32_t) cc.tupdesc->natts;
636 
637  HeapTupleData tuple;
638 
639  POSTGIS_DEBUG(2, "parse_values called");
640  ctx->row_columns = 0;
641 
642  /* Build a temporary HeapTuple control structure */
643  tuple.t_len = HeapTupleHeaderGetDatumLength(ctx->row);
644  ItemPointerSetInvalid(&(tuple.t_self));
645  tuple.t_tableOid = InvalidOid;
646  tuple.t_data = ctx->row;
647 
648  /* We use heap_deform_tuple as it costs only O(N) vs O(N^2) of GetAttributeByNum */
649  heap_deform_tuple(&tuple, cc.tupdesc, cc.values, cc.nulls);
650 
651  POSTGIS_DEBUGF(3, "parse_values natts: %d", natts);
652 
653  for (i = 0; i < natts; i++)
654  {
655  char *key;
656  Oid typoid;
657  uint32_t k;
658  Datum datum = cc.values[i];
659 
660  if (i == ctx->geom_index)
661  continue;
662 
663  if (cc.nulls[i])
664  {
665  POSTGIS_DEBUG(3, "parse_values isnull detected");
666  continue;
667  }
668 
669 #if POSTGIS_PGSQL_VERSION < 110
670  key = cc.tupdesc->attrs[i]->attname.data;
671 #else
672  key = cc.tupdesc->attrs[i].attname.data;
673 #endif
674  k = cc.column_keys_index[i];
675  typoid = cc.column_oid[i];
676 
677 #if POSTGIS_PGSQL_VERSION >= 94
678  if (k == UINT32_MAX && typoid != JSONBOID)
679  elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
680  if (typoid == JSONBOID)
681  {
682  tags = parse_jsonb(ctx, DatumGetJsonbP(datum), tags);
683  continue;
684  }
685 #else
686  if (k == UINT32_MAX)
687  elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
688 #endif
689 
690  switch (typoid)
691  {
692  case BOOLOID:
693  MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,
694  bool_values_hash, bool_value,
695  DatumGetBool, sizeof(protobuf_c_boolean));
696  break;
697  case INT2OID:
698  MVT_PARSE_INT_DATUM(int16_t, DatumGetInt16);
699  break;
700  case INT4OID:
701  MVT_PARSE_INT_DATUM(int32_t, DatumGetInt32);
702  break;
703  case INT8OID:
704  MVT_PARSE_INT_DATUM(int64_t, DatumGetInt64);
705  break;
706  case FLOAT4OID:
708  float_values_hash, float_value,
709  DatumGetFloat4, sizeof(float));
710  break;
711  case FLOAT8OID:
713  double_values_hash, double_value,
714  DatumGetFloat8, sizeof(double));
715  break;
716  default:
717  parse_datum_as_string(ctx, typoid, datum, tags, k);
718  break;
719  }
720  ctx->row_columns++;
721  }
722 
723 
724  ctx->feature->n_tags = ctx->row_columns * 2;
725  ctx->feature->tags = tags;
726 
727  POSTGIS_DEBUGF(3, "parse_values n_tags %zd", ctx->feature->n_tags);
728 }
HeapTupleHeader row
Definition: mvt.h:64
uint32_t row_columns
Definition: mvt.h:78
mvt_column_cache column_cache
Definition: mvt.h:79
bool * nulls
Definition: mvt.h:54
unsigned int uint32_t
Definition: uthash.h:78
uint32_t keys_hash_i
Definition: mvt.h:77
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
uint32_t geom_index
Definition: mvt.h:63
uint32_t * column_keys_index
Definition: mvt.h:51
static uint32_t * parse_jsonb(mvt_agg_context *ctx, Jsonb *jb, uint32_t *tags)
Definition: mvt.c:550
static void parse_datum_as_string(mvt_agg_context *ctx, Oid typoid, Datum datum, uint32_t *tags, uint32_t k)
Definition: mvt.c:536
Datum * values
Definition: mvt.h:53
VectorTile__Tile__Feature * feature
Definition: mvt.h:65
#define MVT_PARSE_DATUM(type, kvtype, hash, valuefield, datumfunc, size)
Definition: mvt.c:497
#define DatumGetJsonbP
Definition: mvt.c:35
uint32_t * column_oid
Definition: mvt.h:52
TupleDesc tupdesc
Definition: mvt.h:55
#define MVT_PARSE_INT_DATUM(type, datumfunc)
Definition: mvt.c:503
Here is the call graph for this function:
Here is the caller graph for this function: