diff options
| -rw-r--r-- | include/fieldstat/fieldstat.h | 4 | ||||
| -rw-r--r-- | src/exporter/cjson_exporter.c | 2 | ||||
| -rw-r--r-- | src/fieldstat.c | 10 | ||||
| -rw-r--r-- | src/tags/cell_manager.c | 9 | ||||
| -rw-r--r-- | src/tags/cell_manager.h | 1 | ||||
| -rw-r--r-- | src/tags/heavy_keeper.c | 4 | ||||
| -rw-r--r-- | src/tags/heavy_keeper.h | 1 |
7 files changed, 22 insertions, 9 deletions
diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h index d184bc4..0e48098 100644 --- a/include/fieldstat/fieldstat.h +++ b/include/fieldstat/fieldstat.h @@ -222,9 +222,9 @@ struct fieldstat_tag_list *fieldstat_get_shared_tags(const struct fieldstat *ins int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags); /* - get the parameter max_n_cell of fieldstat_create_cube. -1 is a valid value, meaning cube has no metric. Return FS_ERR_INVALID_CUBE_ID if cube_id is invalid. + get the cell numbers in a cube. Return FS_ERR_INVALID_CUBE_ID if cube_id is invalid. */ -int fieldstat_get_max_cell_id(const struct fieldstat *instance, int cube_id); +int fieldstat_get_used_sampling(const struct fieldstat *instance, int cube_id); /* * @brief Get the value of a metric of a cell. diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index f9456d1..4055182 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -668,7 +668,7 @@ struct cellwise_rec_for_export *read_tag_and_field(const struct fieldstat *insta size_t n_cell_total = 0; for (int i = 0; i < cube_id_len; i++) { - n_cell_total += fieldstat_get_max_cell_id(instance, cube_id[i]); + n_cell_total += fieldstat_get_used_sampling(instance, cube_id[i]); } free(cube_id); if (n_cell_total == 0) { diff --git a/src/fieldstat.c b/src/fieldstat.c index 0f3cffc..e086ffd 100644 --- a/src/fieldstat.c +++ b/src/fieldstat.c @@ -1032,7 +1032,7 @@ int fieldstat_get_metrics_used_by_cube(const struct fieldstat *instance, int cub int all_available_metric_count = 0; if (cube->valid_metric_arr_len == 0) { - return 0; + return FS_OK; } int *tmp_ids = (int *)malloc(sizeof(int) * cube->valid_metric_arr_len); for (int i = 0; i < cube->valid_metric_arr_len; i++) { @@ -1045,7 +1045,7 @@ int fieldstat_get_metrics_used_by_cube(const struct fieldstat *instance, int cub } if (all_available_metric_count == 0) { free(tmp_ids); - return 0; + return FS_OK; } *metric_id_out = tmp_ids; @@ -1355,16 +1355,14 @@ void fieldstat_get_cells_used_by_cube(const struct fieldstat *instance, int cube *n_cell = n_cell_ret; } -int fieldstat_get_max_cell_id(const struct fieldstat *instance, int cube_id) +int fieldstat_get_used_sampling(const struct fieldstat *instance, int cube_id) { const struct fs_cube *cube = instance->cube[cube_id]; if (cube == NULL) { return FS_ERR_INVALID_CUBE_ID; } - int max_id; - (void)cell_manager_dump(cube->cell_manager, &max_id); - return max_id; + return cell_manager_get_cardinality(cube->cell_manager); } int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags) diff --git a/src/tags/cell_manager.c b/src/tags/cell_manager.c index a77ca3f..f4b767e 100644 --- a/src/tags/cell_manager.c +++ b/src/tags/cell_manager.c @@ -433,6 +433,15 @@ void cell_manager_merge_topk(struct cell_manager *dest, const struct cell_manage heavy_keeper_result_free(result); } +int cell_manager_get_cardinality(const struct cell_manager *pthis) +{ + if (pthis->sampling_mode == SAMPLING_MODE_COMPREHENSIVE) { + return pthis->current_cell_num; + } else { + return heavy_keeper_get_cardinality(pthis->topk_tag_id_map); + } +} + void cube_manager_free(struct cube_manager *pthis) { tag_id_map_free(pthis->head); diff --git a/src/tags/cell_manager.h b/src/tags/cell_manager.h index 3c85abb..b85177c 100644 --- a/src/tags/cell_manager.h +++ b/src/tags/cell_manager.h @@ -17,6 +17,7 @@ const struct tag_hash_key *cell_manager_get_tag_by_cell_id(const struct cell_man long long cell_manager_get_count_by_tag(const struct cell_manager *pthis, const struct tag_hash_key *tag); const struct tag_hash_key **cell_manager_dump(const struct cell_manager *pthis, int *array_len); int cell_manager_find(const struct cell_manager *pthis, const struct tag_hash_key *tag); +int cell_manager_get_cardinality(const struct cell_manager *pthis); int cell_manager_add_cell(struct cell_manager *pthis, const struct tag_hash_key *tag); int cell_manager_add_cell_topk(struct cell_manager *pthis, const struct tag_hash_key *tag, unsigned int count, int *popped_cell_id); diff --git a/src/tags/heavy_keeper.c b/src/tags/heavy_keeper.c index f79c479..39bb4cf 100644 --- a/src/tags/heavy_keeper.c +++ b/src/tags/heavy_keeper.c @@ -276,6 +276,10 @@ struct heavy_keeper_result *heavy_keeper_query(const struct heavy_keeper *hk) { return stats; } +size_t heavy_keeper_get_cardinality(const struct heavy_keeper *hk) { + return sorted_set_cardinality(hk->top_K_heap); +} + int heavy_keeper_query_one(const struct heavy_keeper *hk, const struct tag_hash_key *tag, unsigned int *count_out, int *cell_id_out) { if (count_out != NULL) { diff --git a/src/tags/heavy_keeper.h b/src/tags/heavy_keeper.h index 5d240c2..216d8f6 100644 --- a/src/tags/heavy_keeper.h +++ b/src/tags/heavy_keeper.h @@ -63,6 +63,7 @@ struct heavy_keeper_result *heavy_keeper_query(const struct heavy_keeper *hk); int heavy_keeper_query_one(const struct heavy_keeper *hk, const struct tag_hash_key *tag, unsigned int *count_out, int *cube_id_out); +size_t heavy_keeper_get_cardinality(const struct heavy_keeper *hk); /** * @brief free a heavy keeper query result. * @param stats_hd the pointer to the heavy keeper query result. |
