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

Aggregation operator and accumulator implementations. More...

#include "Aggregation.h"
#include <string>
#include <stdexcept>
#include "utils/lsyscache.h"
#include "utils/elog.h"
#include "provsql_error.h"
Include dependency graph for Aggregation.cpp:

Go to the source code of this file.

Classes

struct  False<... >
struct  StandardAgg< T >
 Base aggregator template for scalar types (int, float, bool, string). More...
struct  SumAgg< T >
 Aggregator implementing SUM for integer or float types. More...
struct  MinAgg< T >
 Aggregator implementing MIN for integer or float types. More...
struct  MaxAgg< T >
 Aggregator implementing MAX for integer or float types. More...
struct  ChooseAgg< T >
 Aggregator implementing CHOOSE (returns the first non-NULL input). More...
struct  AvgAgg< T >
 Aggregator implementing AVG; always returns a float result. 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

Aggregation operator and accumulator implementations.

Implements the two factory functions declared in Aggregation.h:

Each built aggregation function × value-type combination has its own Aggregator subclass defined locally in this file (e.g. SumAgg<long>, MinAgg<double>, ChooseAgg<long>). Only the aggregates the Monte-Carlo sampler and the subset enumerator evaluate directly are built: the numeric ones (SUM / COUNT / MIN / MAX / AVG) and CHOOSE (the categorical analog, decided by the exhaustive subset enumerator). The boolean (bool_or / bool_and) and array_agg aggregates are resolved to a Boolean subcircuit by the m-semiring HAVING rewrite (having_semantics) and so never reach makeAggregator.

Definition in file Aggregation.cpp.

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 71 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 34 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 230 of file Aggregation.cpp.

Here is the caller graph for this function: