ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Aggregation.h File Reference

Typed aggregation value, operator, and aggregator abstractions. More...

#include "postgres.h"
#include <variant>
#include <string>
#include <vector>
#include <cassert>
#include <memory>
Include dependency graph for Aggregation.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AggValue
 A dynamically-typed aggregate value. More...
struct  Aggregator
 Abstract interface for an incremental aggregate accumulator. More...

Enumerations

enum class  ComparisonOperator {
  EQ , NE , LE , LT ,
  GE , GT
}
 SQL comparison operators used in gate_cmp circuit gates. More...
enum class  AggregationOperator {
  COUNT , SUM , MIN , MAX ,
  AVG , AND , OR , CHOOSE ,
  ARRAY_AGG , NONE
}
 SQL aggregation functions tracked by ProvSQL. More...
enum class  ValueType {
  INT , FLOAT , BOOLEAN , STRING ,
  ARRAY_INT , ARRAY_FLOAT , ARRAY_BOOLEAN , ARRAY_STRING ,
  NONE
}
 Runtime type tag for aggregate values. More...

Functions

AggregationOperator getAggregationOperator (Oid oid)
 Map a PostgreSQL aggregate function OID to an AggregationOperator.
ComparisonOperator cmpOpFromOid (Oid op_oid, bool &ok)
 Map a PostgreSQL comparison-operator OID to a ComparisonOperator.
std::unique_ptr< AggregatormakeAggregator (AggregationOperator op, ValueType t)
 Create a concrete Aggregator for the given operator and value type.

Detailed Description

Typed aggregation value, operator, and aggregator abstractions.

This header provides the type system used by ProvSQL's aggregate provenance evaluation:

  • ComparisonOperator: the six standard SQL comparison operators, used by gate_cmp gates in the circuit.
  • AggregationOperator: the SQL aggregation functions that ProvSQL tracks provenance for (COUNT, SUM, MIN, MAX, AVG, AND, OR, …).
  • ValueType: the runtime type tag for aggregate values.
  • AggValue: a tagged union holding one aggregate value of any supported type, built on std::variant.
  • Aggregator: an abstract interface for stateful incremental accumulators, one per aggregation function/type combination.

The free functions getAggregationOperator() and makeAggregator() map PostgreSQL OIDs and operator/type pairs to the corresponding C++ objects.

Definition in file Aggregation.h.

Enumeration Type Documentation

◆ AggregationOperator

enum class AggregationOperator
strong

SQL aggregation functions tracked by ProvSQL.

Enumerator
COUNT 

COUNT(*) or COUNT(expr) → integer.

SUM 

SUM → integer or float.

MIN 

MIN → input type.

MAX 

MAX → input type.

AVG 

AVG → float.

AND 

Boolean AND aggregate.

OR 

Boolean OR aggregate.

CHOOSE 

Arbitrary selection (pick one element).

ARRAY_AGG 

Array aggregation.

NONE 

No aggregation (returns NULL).

Definition at line 50 of file Aggregation.h.

◆ ComparisonOperator

enum class ComparisonOperator
strong

SQL comparison operators used in gate_cmp circuit gates.

Enumerator
EQ 

Equal (=).

NE 

Not equal (<>).

LE 

Less than or equal (<=).

LT 

Less than (<).

GE 

Greater than or equal (>=).

GT 

Greater than (>).

Definition at line 38 of file Aggregation.h.

◆ ValueType

enum class ValueType
strong

Runtime type tag for aggregate values.

Enumerator
INT 

Signed 64-bit integer.

FLOAT 

Double-precision float.

BOOLEAN 

Boolean.

STRING 

Text string.

ARRAY_INT 

Array of integers.

ARRAY_FLOAT 

Array of floats.

ARRAY_BOOLEAN 

Array of booleans.

ARRAY_STRING 

Array of strings.

NONE 

No value (NULL).

Definition at line 66 of file Aggregation.h.

Function Documentation

◆ cmpOpFromOid()

ComparisonOperator cmpOpFromOid ( Oid op_oid,
bool & ok )

Map a PostgreSQL comparison-operator OID to a ComparisonOperator.

The OID is the one stored in gate_cmp's info1 field (the OID of one of the six standard comparators =, <>, <, <=, >, >=). The translation goes via get_opname() so it is operand-type agnostic.

Parameters
[in]op_oidComparison-operator OID.
[out]okSet to true on a recognised comparator, false when op_oid does not resolve in pg_operator or its name is not one of the six standard ones.
Returns
The matching ComparisonOperator on success; an unspecified value (currently EQ) when ok is false.

Definition at line 66 of file Aggregation.cpp.

Here is the caller graph for this function:

◆ getAggregationOperator()

AggregationOperator getAggregationOperator ( Oid oid)

Map a PostgreSQL aggregate function OID to an AggregationOperator.

Parameters
oidOID of the aggregate function (e.g. F_COUNT_ANY, F_SUM_INT4).
Returns
The corresponding AggregationOperator.

Definition at line 29 of file Aggregation.cpp.

Here is the caller graph for this function:

◆ makeAggregator()

std::unique_ptr< Aggregator > makeAggregator ( AggregationOperator op,
ValueType t )

Create a concrete Aggregator for the given operator and value type.

Parameters
opThe aggregation function to implement.
tThe type of input values that will be accumulated.
Returns
A heap-allocated Aggregator, or nullptr if the combination is not supported.

Definition at line 316 of file Aggregation.cpp.

Here is the caller graph for this function: