12#include "catalog/pg_type.h"
13#include "utils/lsyscache.h"
19#include <unordered_set>
32 case TEXTOID:
case VARCHAROID:
case BPCHAROID:
case CHAROID:
case NAMEOID:
41 case INT2OID:
case INT4OID:
case INT8OID:
49 return oid == BOOLOID;
59 Oid elem = get_element_type(oid);
60 return elem == BOOLOID;
68 case INT2OID:
case INT4OID:
case INT8OID:
69 case FLOAT4OID:
case FLOAT8OID:
case NUMERICOID:
83 size_t i = 0, n = s.size();
84 while (i < n && isspace((
unsigned char) s[i])) i++;
85 if (i >= n || s[i] !=
'{')
return false;
87 while (i < n && isspace((
unsigned char) s[i])) i++;
88 if (i < n && s[i] ==
'}')
return true;
91 while (i < n && isspace((
unsigned char) s[i])) i++;
92 if (i < n && s[i] ==
'"') {
94 while (i < n && s[i] !=
'"') {
95 if (s[i] ==
'\\' && i + 1 < n) { elem.push_back(s[i + 1]); i += 2; }
96 else { elem.push_back(s[i]); i++; }
98 if (i >= n)
return false;
101 while (i < n && s[i] !=
',' && s[i] !=
'}') { elem.push_back(s[i]); i++; }
102 while (!elem.empty() && isspace((
unsigned char) elem.back())) elem.pop_back();
105 while (i < n && isspace((
unsigned char) s[i])) i++;
106 if (i < n && s[i] ==
',') { i++;
continue; }
107 if (i < n && s[i] ==
'}')
return true;
118 if (s.empty())
return false;
121 if (s[i] ==
'+' || s[i] ==
'-') { neg = (s[i] ==
'-'); ++i; }
124 bool seen_dot =
false, seen_digit =
false;
125 for (; i < s.size(); ++i) {
128 if (seen_dot)
return false;
130 }
else if (ch >=
'0' && ch <=
'9') {
131 digits.push_back(ch);
138 if (!seen_digit)
return false;
145 while (sc > 0 && !digits.empty() && digits.back() ==
'0') {
151 long long val = std::stoll(digits, &pos);
152 if (pos != digits.size())
return false;
153 mantissa = neg ? -
static_cast<long>(val) :
static_cast<long>(val);
163bool rescale_to(
long mantissa,
int scale,
int target_scale,
long &out) {
165 for (
int k = 0; k < target_scale - scale; ++k) {
166 if (factor > (LONG_MAX / 10))
return false;
170 (mantissa > LONG_MAX / factor || mantissa < LONG_MIN / factor))
172 out = mantissa * factor;
204 const auto &w = c.
getWires(semimod_gate);
205 if (w.size() != 2)
return false;
253 std::vector<gate_t> out;
254 std::vector<gate_t> stack;
255 stack.push_back(start);
257 std::unordered_set<gate_t> seen;
259 while (!stack.empty()) {
260 gate_t cur = stack.back();
263 if (!seen.insert(cur).second)
continue;
267 if (cw.size() == 2) {
282 for (
gate_t ch : w) stack.push_back(ch);
ComparisonOperator cmpOpFromOid(Oid op_oid, bool &ok)
Map a PostgreSQL comparison-operator OID to a ComparisonOperator.
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.
Fix macro conflicts between PostgreSQL headers and the C++ STL/Boost.
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
gateType getGateType(gate_t g) const
Return the type of gate g.
In-memory provenance circuit with semiring-generic evaluation.
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.
Provenance evaluation helper for HAVING-clause circuits.
bool rescale_to(long mantissa, int scale, int target_scale, long &out)
bool aggtype_is_text(unsigned oid)
bool aggtype_is_numeric(unsigned oid)
bool aggtype_is_integer(unsigned oid)
bool parse_array_literal(const std::string &s, std::vector< std::string > &out)
ComparisonOperator flip_op(ComparisonOperator op)
static bool side_has_agg(GenericCircuit &c, gate_t g)
bool aggtype_elem_is_boolean(unsigned oid)
std::vector< gate_t > collect_sp_cmp_gates(GenericCircuit &c, gate_t start)
bool parse_decimal_scaled(const std::string &s, long &mantissa, int &scale)
ComparisonOperator map_cmp_op(GenericCircuit &c, gate_t cmp_gate, bool &ok)
bool aggtype_is_boolean(unsigned oid)
bool semimod_extract_string_and_K(GenericCircuit &c, gate_t semimod_gate, std::string &m_out, gate_t &k_gate_out)
bool extract_constant_string(GenericCircuit &c, gate_t x, std::string &C_out)
@ gate_arith
n-ary arithmetic gate over scalar-valued children (info1 holds operator tag)