PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ nd_stats_to_json()

static char* nd_stats_to_json ( const ND_STATS nd_stats)
static

Convert an ND_STATS to a JSON representation for external use.

Definition at line 435 of file gserialized_estimate.c.

References ND_STATS_T::cells_covered, ND_STATS_T::extent, ND_STATS_T::histogram_cells, ND_STATS_T::histogram_features, nd_box_to_json(), ND_STATS_T::ndims, ND_STATS_T::not_null_features, ND_STATS_T::sample_features, ND_STATS_T::size, stringbuffer_append(), stringbuffer_aprintf(), stringbuffer_create(), stringbuffer_destroy(), stringbuffer_getstringcopy(), and ND_STATS_T::table_features.

Referenced by _postgis_gserialized_stats(), compute_gserialized_stats_mode(), estimate_join_selectivity(), and gserialized_gist_sel().

436 {
437  char *json_extent, *str;
438  int d;
440  int ndims = (int)roundf(nd_stats->ndims);
441 
442  stringbuffer_append(sb, "{");
443  stringbuffer_aprintf(sb, "\"ndims\":%d,", ndims);
444 
445  /* Size */
446  stringbuffer_append(sb, "\"size\":[");
447  for ( d = 0; d < ndims; d++ )
448  {
449  if ( d ) stringbuffer_append(sb, ",");
450  stringbuffer_aprintf(sb, "%d", (int)roundf(nd_stats->size[d]));
451  }
452  stringbuffer_append(sb, "],");
453 
454  /* Extent */
455  json_extent = nd_box_to_json(&(nd_stats->extent), ndims);
456  stringbuffer_aprintf(sb, "\"extent\":%s,", json_extent);
457  pfree(json_extent);
458 
459  stringbuffer_aprintf(sb, "\"table_features\":%d,", (int)roundf(nd_stats->table_features));
460  stringbuffer_aprintf(sb, "\"sample_features\":%d,", (int)roundf(nd_stats->sample_features));
461  stringbuffer_aprintf(sb, "\"not_null_features\":%d,", (int)roundf(nd_stats->not_null_features));
462  stringbuffer_aprintf(sb, "\"histogram_features\":%d,", (int)roundf(nd_stats->histogram_features));
463  stringbuffer_aprintf(sb, "\"histogram_cells\":%d,", (int)roundf(nd_stats->histogram_cells));
464  stringbuffer_aprintf(sb, "\"cells_covered\":%d", (int)roundf(nd_stats->cells_covered));
465  stringbuffer_append(sb, "}");
466 
467  str = stringbuffer_getstringcopy(sb);
469  return str;
470 }
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:35
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string...
Definition: stringbuffer.c:160
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided...
Definition: stringbuffer.c:253
float4 size[ND_DIMS]
static char * nd_box_to_json(const ND_BOX *nd_box, int ndims)
Convert an ND_BOX to a JSON string for printing.
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.c:134
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:78
Here is the call graph for this function:
Here is the caller graph for this function: