ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
agg_token.h
Go to the documentation of this file.
1/**
2 * @file agg_token.h
3 * @brief Aggregate-provenance token type used in SQL aggregate functions.
4 *
5 * Defines the @c agg_token composite type that pairs a provenance circuit
6 * UUID (as a hex string) with an aggregate running value. It is passed
7 * between the transition and final functions of ProvSQL's custom
8 * aggregate operators so that both the provenance token and its
9 * associated numeric value travel together through a GROUP BY query.
10 */
11#ifndef AGG_TOKEN_H
12#define AGG_TOKEN_H
13
14#include "provsql_utils.h"
15
16/**
17 * @brief Aggregate token bundling a provenance UUID with a running value.
18 *
19 * @c tok holds the UUID of the provenance circuit gate for the current
20 * aggregate group, formatted as a 36-character string
21 * (@c xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx plus a NUL terminator).
22 * The buffer size @c 2*UUID_LEN+5 accommodates the standard UUID text
23 * representation.
24 *
25 * @c val holds the textual representation of the current aggregate value
26 * (e.g., a decimal integer or floating-point number). A longer value (the
27 * text of a @c string_agg, an array, a multirange...) keeps its first
28 * @c AGG_TOKEN_PREFIX_LEN characters, and the last byte of @c val is set to
29 * @c AGG_TOKEN_TRUNCATED: the whole value is that of the gate, read by
30 * @c agg_token_value_cstring.
31 */
32typedef struct agg_token {
33 char tok[2*UUID_LEN+5]; ///< Provenance UUID as a text string
34 char val[80]; ///< Aggregate running value as a text string
35} agg_token;
36
37/** @brief Length of the prefix of a value too long for @c agg_token::val. */
38#define AGG_TOKEN_PREFIX_LEN (sizeof(((agg_token *)0)->val) - 2)
39/** @brief Last byte of @c agg_token::val when the value is a prefix. */
40#define AGG_TOKEN_TRUNCATED '\x01'
41
42void agg_token_set_value(agg_token *aggtok, const char *val, size_t len);
43const char *agg_token_value_cstring(const agg_token *aggtok);
44
45#endif /* AGG_TOKEN_H */
void agg_token_set_value(agg_token *aggtok, const char *val, size_t len)
Set the value of aggtok to the len first bytes of val.
Definition agg_token.c:36
const char * agg_token_value_cstring(const agg_token *aggtok)
The value of aggtok, as a C string.
Definition agg_token.c:55
Core types, constants, and utilities shared across ProvSQL.
Aggregate token bundling a provenance UUID with a running value.
Definition agg_token.h:32
char val[80]
Aggregate running value as a text string.
Definition agg_token.h:34
char tok[2 *UUID_LEN+5]
Provenance UUID as a text string.
Definition agg_token.h:33