ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
having_semantics.hpp
Go to the documentation of this file.
1/**
2 * @file having_semantics.hpp
3 * @brief Provenance evaluation helpers for HAVING-clause circuits.
4 *
5 * When a query includes a HAVING clause, ProvSQL creates a special
6 * sub-circuit that encodes the aggregate predicate. Before the main
7 * provenance circuit can be evaluated over a semiring, these HAVING
8 * sub-circuits must first be evaluated to determine which groups
9 * pass the filter.
10 *
11 * This header declares one evaluation helper per semiring variant.
12 * Each function evaluates the HAVING sub-circuit rooted at gate @p g
13 * over the appropriate semiring, writing results into @p mapping.
14 * On successful evaluation, @p mapping is populated with entries
15 * for input gates reachable from @p g. If the HAVING gate type is
16 * incompatible with the requested semiring the function is a no-op.
17 */
18#ifndef PROVSQL_HAVING_SEMANTICS_HPP
19#define PROVSQL_HAVING_SEMANTICS_HPP
20#include <string>
21#include <unordered_map>
22
23#include "GenericCircuit.hpp"
24#include "BooleanCircuit.h"
25#include "semiring/BoolExpr.h"
26#include "semiring/Why.h"
27
28/**
29 * @brief Evaluate the HAVING sub-circuit at @p g over the Formula semiring.
30 *
31 * @param c The generic circuit containing gate @p g.
32 * @param g Root gate of the HAVING sub-circuit.
33 * @param mapping Map from input gates to their formula string values;
34 * populated on successful evaluation.
35 */
38 gate_t g,
39 std::unordered_map<gate_t, std::string> &mapping
40 );
41
42/**
43 * @brief Evaluate the HAVING sub-circuit at @p g over the Counting semiring.
44 *
45 * @param c The generic circuit containing gate @p g.
46 * @param g Root gate of the HAVING sub-circuit.
47 * @param mapping Map from input gates to their count values;
48 * populated on successful evaluation.
49 */
52 gate_t g,
53 std::unordered_map<gate_t, unsigned> &mapping
54 );
55
56/**
57 * @brief Evaluate the HAVING sub-circuit at @p g over the Why-provenance semiring.
58 *
59 * @param c The generic circuit containing gate @p g.
60 * @param g Root gate of the HAVING sub-circuit.
61 * @param mapping Map from input gates to their why-provenance values;
62 * populated on successful evaluation.
63 */
66 gate_t g,
67 std::unordered_map<gate_t, semiring::why_provenance_t> &mapping
68 );
69
70/**
71 * @brief Evaluate the HAVING sub-circuit at @p g over the BoolExpr semiring.
72 *
73 * @param c The generic circuit containing gate @p g.
74 * @param be The @c BoolExpr semiring instance (shared circuit).
75 * @param g Root gate of the HAVING sub-circuit.
76 * @param mapping Map from input gates to their @c gate_t values in @c be;
77 * populated on successful evaluation.
78 */
82 gate_t g,
83 std::unordered_map<gate_t, gate_t> &mapping
84 );
85
86/**
87 * @brief Evaluate the HAVING sub-circuit at @p g over the Boolean semiring.
88 *
89 * @param c The generic circuit containing gate @p g.
90 * @param g Root gate of the HAVING sub-circuit.
91 * @param mapping Map from input gates to their Boolean values;
92 * populated on successful evaluation.
93 */
96 gate_t g,
97 std::unordered_map<gate_t, bool> &mapping
98 );
99
100#endif
Boolean-expression (lineage formula) semiring.
Boolean provenance circuit with support for knowledge compilation.
gate_t
Strongly-typed gate identifier.
Definition Circuit.h:48
Template implementation of GenericCircuit::evaluate().
Why-provenance semiring (set of witness sets).
In-memory provenance circuit with semiring-generic evaluation.
Provenance-as-Boolean-circuit semiring.
Definition BoolExpr.h:42
void provsql_try_having_why(GenericCircuit &c, gate_t g, std::unordered_map< gate_t, semiring::why_provenance_t > &mapping)
Evaluate the HAVING sub-circuit at g over the Why-provenance semiring.
void provsql_try_having_counting(GenericCircuit &c, gate_t g, std::unordered_map< gate_t, unsigned > &mapping)
Evaluate the HAVING sub-circuit at g over the Counting semiring.
void provsql_try_having_boolean(GenericCircuit &c, gate_t g, std::unordered_map< gate_t, bool > &mapping)
Evaluate the HAVING sub-circuit at g over the Boolean semiring.
void provsql_try_having_formula(GenericCircuit &c, gate_t g, std::unordered_map< gate_t, std::string > &mapping)
Evaluate the HAVING sub-circuit at g over the Formula semiring.
void provsql_try_having_boolexpr(GenericCircuit &c, semiring::BoolExpr &be, gate_t g, std::unordered_map< gate_t, gate_t > &mapping)
Evaluate the HAVING sub-circuit at g over the BoolExpr semiring.