19#include "catalog/pg_type.h"
20#include "utils/uuid.h"
21#include "executor/spi.h"
22#include "utils/builtins.h"
46 s=s.substr(1,s.size()-2);
48 vector<pair<int,int> > result;
52 while(getline(iss, p,
'}'))
54 if(!p.empty() && p[0]==
',')
58 string s1=p.substr(1,k-1);
63 i1=stoi(p.substr(1,k-1));
64 int i2=stoi(p.substr(k+1,p.size()-k));
65 result.push_back(make_pair(i1,i2));
79 Datum arguments[1]={token};
82 char nulls[1] = {
' '};
88 if(SPI_execute_with_args(
89 "SELECT * FROM provsql.sub_circuit_for_where($1)", 1, argtypes, arguments, nulls,
true, 0)
91 int proc = SPI_processed;
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);
101 if(type ==
"input") {
102 string table = SPI_getvalue(tuple, tupdesc, 4);
103 int nb_columns = stoi(SPI_getvalue(tuple, tupdesc, 5));
109 if(type ==
"times") {
111 }
else if(type ==
"plus") {
113 }
else if(type ==
"project") {
114 vector<pair<int,int> > v =
parse_array(SPI_getvalue(tuple, tupdesc, 7));
115 sort(v.begin(), v.end(), [](
auto &left,
auto &right) {
116 return left.second < right.second;
120 infos.push_back(p.first);
123 }
else if(type ==
"eq") {
124 vector<pair<int,int> > v =
parse_array(std::string(
"{")+SPI_getvalue(tuple, tupdesc, 6)+
"}");
128 }
else if(type ==
"monusr" || type ==
"monusl" || type ==
"monus") {
129 provsql_error(
"Where-provenance of non-monotone query not supported");
137 provsql_error(
"SPI_execute_with_args failed on provsql.sub_circuit_for_where");
144 vector<set<WhereCircuit::Locator> > v = c.
evaluate(gate);
172 Datum token = PG_GETARG_DATUM(0);
175 }
catch(
const std::exception &e) {
Where-provenance circuit tracking column-level data origin.
@ PLUS
Sum (disjunction) of child where-provenance sets.
@ TIMES
Product (conjunction) of child where-provenance sets.
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 encoding where-provenance (column-level data origin).
gate_t setGateInput(const uuid &u, std::string table, int nb_columns)
Create an input gate for a specific table row.
gate_t setGateEquality(const uuid &u, int pos1, int pos2)
Create an equality (equijoin) gate for two attribute positions.
gate_t setGate(const uuid &u, WhereGate type) override
Create or update the gate associated with UUID u.
gate_t setGateProjection(const uuid &u, std::vector< int > &&infos)
Create a projection gate with column mapping.
std::vector< std::set< Locator > > evaluate(gate_t g) const
Evaluate the where-provenance circuit at gate g.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
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.
string UUIDDatum2string(Datum token)
Convert a PostgreSQL Datum holding a UUID to a std::string.
C++ utility functions for UUID manipulation.
Structure to store the value of various constants.
Oid OID_TYPE_UUID
OID of the uuid TYPE.
Datum where_provenance(PG_FUNCTION_ARGS)
PostgreSQL-callable wrapper for where_provenance().
static string where_provenance_internal(Datum token)
Build a JSON where-provenance description for the circuit rooted at token.
static vector< pair< int, int > > parse_array(string s)
Parse a PostgreSQL text representation of an array of integer pairs.