18#include "catalog/pg_type.h"
19#include "utils/uuid.h"
20#include "executor/spi.h"
42 s = s.substr(1, s.size() - 2);
44 vector<pair<int, int> > result;
49 while(getline(iss, p,
'}'))
51 if(!p.empty() && p[0]==
',')
54 int k = p.find(
",", 1);
55 string s1 = p.substr(1, k - 1);
57 if (s1 ==
"NULL" || s1 ==
"")
60 i1 = stoi(p.substr(1, k - 1));
61 int i2 = stoi(p.substr(k + 1, p.size() - k));
62 result.push_back(make_pair(i1, i2));
77 Datum arguments[2]={token,token2prob};
80 char nulls[2] = {
' ',
' '};
88 if (SPI_execute_with_args(
89 "SELECT * FROM provsql.sub_circuit_with_desc($1,$2)", 2, argtypes, arguments, nulls,
true, 0) == SPI_OK_SELECT)
92 TupleDesc tupdesc = SPI_tuptable->tupdesc;
93 SPITupleTable *tuptable = SPI_tuptable;
95 for (
int i = 0; i < proc; i++)
97 HeapTuple tuple = tuptable->vals[i];
99 string f = SPI_getvalue(tuple, tupdesc, 1);
100 string type = SPI_getvalue(tuple, tupdesc, 3);
112 else if (type ==
"plus")
116 else if (type ==
"monus")
120 else if (type ==
"monusr")
124 else if (type ==
"monusl")
128 else if (type ==
"delta")
132 else if (type ==
"eq")
134 vector<pair<int, int> > v =
parse_array(std::string(
"{")+SPI_getvalue(tuple, tupdesc, 5)+
"}");
137 std::string cond = std::to_string(v[0].first) + std::string(
"=") + std::to_string(v[0].second);
140 else if (type ==
"project")
142 vector<pair<int, int> > v =
parse_array(SPI_getvalue(tuple, tupdesc, 6));
143 sort(v.begin(), v.end(), [](
auto &left,
auto &right) {
144 return left.second < right.second;
146 std::string cond(
"(");
149 cond += std::to_string(p.first) +
",";
151 std::string cond_final(cond.substr(0, cond.size() - 1) +
")");
168 int display = DatumGetInt64(is_debug);
181 Datum token = PG_GETARG_DATUM(0);
182 Datum token2prob = PG_GETARG_DATUM(1);
183 Datum is_debug = PG_GETARG_DATUM(2);
190 text *result = (text *) palloc(VARHDRSZ + s.size() + 1);
191 SET_VARSIZE(result, VARHDRSZ + s.size());
193 memcpy((
void *) VARDATA(result),
196 PG_RETURN_TEXT_P(result);
197 }
catch(
const std::exception &e) {
gate_t
Strongly-typed gate identifier.
Provenance circuit variant that renders to GraphViz DOT format.
@ PROJECT
Projection gate.
@ OMINUS
Semiring monus (⊖), full.
@ OMINUSL
Monus, left child only.
@ OMINUSR
Monus, right child only.
@ DELTA
δ-semiring operator
@ IN
Input (variable) gate.
@ OTIMES
Semiring times (⊗)
void addWire(gate_t f, gate_t t)
Add a directed wire from gate f (parent) to gate t (child).
gate_t getGate(const uuid &u)
Return (or create) the gate associated with UUID u.
Circuit specialisation for GraphViz DOT rendering.
virtual std::string toString(gate_t g) const override
Return a textual description of gate g for debugging.
gate_t setGate(const uuid &u, DotGate type) override
Create or update the gate associated with UUID u.
std::string render() const
Render the entire circuit as a GraphViz DOT digraph string.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
#define provsql_warning(fmt,...)
Emit a ProvSQL warning message (execution continues).
Shared-memory segment and inter-process pipe management.
constants_t get_constants(bool failure_if_not_possible)
Retrieve the cached OID constants for the current database.
Core types, constants, and utilities shared across ProvSQL.
Structure to store the value of various constants.
Oid OID_TYPE_UUID
OID of the uuid TYPE.
static std::string view_circuit_internal(Datum token, Datum token2prob, Datum is_debug)
Build a GraphViz DOT representation of the provenance circuit at token.
Datum view_circuit(PG_FUNCTION_ARGS)
PostgreSQL-callable wrapper for view_circuit().
static vector< pair< int, int > > parse_array(string s)
Parse a PostgreSQL text representation of an array of integer pairs.