31#include "utils/lsyscache.h"
34template<
typename S, std::enable_if_t<std::is_base_of_v<semiring::Semiring<
typename S::value_type>, S>,
int> >
37 const auto it = provenance_mapping.find(g);
38 if(it != provenance_mapping.end())
58 std::vector<typename S::value_type> childrenResult;
59 std::transform(children.begin(), children.end(), std::back_inserter(childrenResult), [&](
auto u) {
60 return evaluate<S>(u, provenance_mapping, semiring);
63 childrenResult.erase(std::remove(std::begin(childrenResult), std::end(childrenResult),
semiring.zero()),
64 childrenResult.end());
65 return semiring.plus(childrenResult);
67 for(
const auto &c: childrenResult) {
71 childrenResult.erase(std::remove(std::begin(childrenResult), std::end(childrenResult),
semiring.one()),
72 childrenResult.end());
73 return semiring.times(childrenResult);
75 if(childrenResult[0]==
semiring.zero() || childrenResult[0]==childrenResult[1])
78 return semiring.monus(childrenResult[0], childrenResult[1]);
93 char * opname = get_opname(
infos.first);
97 std::string func_name {opname};
101 if(func_name ==
"=") {
103 }
else if(func_name ==
"<=") {
105 }
else if(func_name ==
"<") {
107 }
else if(func_name ==
">") {
109 }
else if(func_name ==
">=") {
111 }
else if(func_name ==
"<>") {
114 throw CircuitException(
"Comparison operator " + func_name +
" not supported");
129 std::vector<typename S::value_type> vec;
131 vec.push_back(evaluate<S>(*it, provenance_mapping,
semiring));
AggregationOperator getAggregationOperator(Oid oid)
Map a PostgreSQL aggregate function OID to an AggregationOperator.
AggregationOperator
SQL aggregation functions tracked by ProvSQL.
ComparisonOperator
SQL comparison operators used in gate_cmp circuit gates.
@ LE
Less than or equal (<=)
@ GE
Greater than or equal (>=)
gate_t
Strongly-typed gate identifier.
Semiring-agnostic in-memory provenance circuit.
Exception type thrown by circuit operations on invalid input.
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
gate_type getGateType(gate_t g) const
Return the type of gate g.
std::map< gate_t, std::pair< unsigned, unsigned > > infos
Per-gate (info1, info2) annotations.
S::value_type evaluate(gate_t g, std::unordered_map< gate_t, typename S::value_type > &provenance_mapping, S semiring) const
Evaluate the sub-circuit rooted at gate g over semiring semiring.
std::string getExtra(gate_t g) const
Return the string extra for gate g.
std::pair< unsigned, unsigned > getInfos(gate_t g) const
Return the integer annotation pair for gate g.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
@ gate_update
Update operation.
@ gate_monus
M-Semiring monus.
@ gate_eq
Equijoin gate (for where provenance)
@ gate_value
Scalar value (for aggregate provenance)
@ gate_delta
δ-semiring operator (see Amsterdamer, Deutch, Tannen, PODS 2011)
@ gate_mulinput
Multivalued input (for Boolean provenance)
@ gate_zero
Semiring zero.
@ gate_agg
Aggregation operator (for aggregate provenance)
@ gate_project
Project gate (for where provenance)
@ gate_times
Semiring times.
@ gate_cmp
Currently unused, meant for comparison of aggregate values.
@ gate_plus
Semiring plus.
@ gate_semimod
Semimodule scalar multiplication (for aggregate provenance)
@ gate_input
Input (variable) gate of the circuit.