Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7ca1bf7
Update vendored DuckDB sources to 9612b5bea5
duckdblabs-bot Jan 21, 2026
0752b2a
Update vendored DuckDB sources to 3f41e38ba7
duckdblabs-bot Jan 23, 2026
fa831e3
Update vendored DuckDB sources to 5a115ef952
duckdblabs-bot Feb 2, 2026
7606c5e
Update vendored DuckDB sources to e5fb0a7eab
duckdblabs-bot Feb 3, 2026
14eb04c
Update vendored DuckDB sources to d9122b9075
duckdblabs-bot Feb 5, 2026
67fcf0e
Update vendored DuckDB sources to e55e16c21c
duckdblabs-bot Feb 6, 2026
848d469
Update vendored DuckDB sources to e0ff645498
duckdblabs-bot Feb 11, 2026
7c9b325
Update vendored DuckDB sources to 344094eb03
duckdblabs-bot Feb 12, 2026
91f6289
Update vendored DuckDB sources to 5c4f75c96f
duckdblabs-bot Feb 14, 2026
fc9bb5b
Update vendored DuckDB sources to a25cf61616
duckdblabs-bot Feb 17, 2026
9602143
Update vendored DuckDB sources to 28e04ed429
duckdblabs-bot Feb 18, 2026
7335f1a
Update vendored DuckDB sources to 9092e4458d
duckdblabs-bot Feb 19, 2026
529db60
Update vendored DuckDB sources to 3b7e40132e
duckdblabs-bot Feb 20, 2026
581ac6a
Update vendored DuckDB sources to f961e485d6
duckdblabs-bot Feb 21, 2026
db2421b
Update vendored DuckDB sources to 0ae55359dd
duckdblabs-bot Feb 26, 2026
c203088
Update vendored DuckDB sources to c43d12535f
duckdblabs-bot Feb 27, 2026
b74e2b0
Update vendored DuckDB sources to dc11eadd8f
duckdblabs-bot Mar 7, 2026
8b06afe
Update vendored DuckDB sources to c467bc561f
duckdblabs-bot Mar 14, 2026
f809683
Update vendored DuckDB sources to 0bf859fca7
duckdblabs-bot Mar 16, 2026
dfa5e72
Update vendored DuckDB sources to e3509341f6
duckdblabs-bot Mar 17, 2026
93b69b7
Update vendored DuckDB sources to ee6e77c3a4
duckdblabs-bot Mar 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
410 changes: 367 additions & 43 deletions CMakeLists.txt

Large diffs are not rendered by default.

52 changes: 40 additions & 12 deletions src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,47 @@ struct TimeTZAverageOperation : public BaseSumOperation<AverageSetOperation, Add
}
};

LogicalType GetAvgStateType(const AggregateFunction &function) {
child_list_t<LogicalType> children;
children.emplace_back("count", LogicalType::UBIGINT);
children.emplace_back("value", function.arguments[0]);
return LogicalType::STRUCT(std::move(children));
}

LogicalType GetKahanAvgStateType(const AggregateFunction &function) {
child_list_t<LogicalType> children;
children.emplace_back("count", LogicalType::UBIGINT);
children.emplace_back("value", LogicalType::DOUBLE);
children.emplace_back("err", LogicalType::DOUBLE);
return LogicalType::STRUCT(std::move(children));
}

AggregateFunction GetAverageAggregate(PhysicalType type) {
switch (type) {
case PhysicalType::INT16: {
return AggregateFunction::UnaryAggregate<AvgState<int64_t>, int16_t, double, IntegerAverageOperation>(
LogicalType::SMALLINT, LogicalType::DOUBLE);
LogicalType::SMALLINT, LogicalType::DOUBLE)
.SetStructStateExport(GetAvgStateType);
}
case PhysicalType::INT32: {
return AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, int32_t, double, IntegerAverageOperationHugeint>(
LogicalType::INTEGER, LogicalType::DOUBLE);
LogicalType::INTEGER, LogicalType::DOUBLE)
.SetStructStateExport(GetAvgStateType);
}
case PhysicalType::INT64: {
return AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, int64_t, double, IntegerAverageOperationHugeint>(
LogicalType::BIGINT, LogicalType::DOUBLE);
LogicalType::BIGINT, LogicalType::DOUBLE)
.SetStructStateExport(GetAvgStateType);
}
case PhysicalType::INT128: {
return AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, hugeint_t, double, HugeintAverageOperation>(
LogicalType::HUGEINT, LogicalType::DOUBLE);
LogicalType::HUGEINT, LogicalType::DOUBLE)
.SetStructStateExport(GetAvgStateType);
}
case PhysicalType::INTERVAL: {
return AggregateFunction::UnaryAggregate<IntervalAvgState, interval_t, interval_t, IntervalAverageOperation>(
LogicalType::INTERVAL, LogicalType::INTERVAL);
LogicalType::INTERVAL, LogicalType::INTERVAL)
.SetStructStateExport(GetAvgStateType);
}
default:
throw InternalException("Unimplemented average aggregate");
Expand All @@ -282,6 +302,7 @@ unique_ptr<FunctionData> BindDecimalAvg(ClientContext &context, AggregateFunctio
AggregateFunctionSet AvgFun::GetFunctions() {
AggregateFunctionSet avg;

// The first is already opted-in during `BindDecimalAvg`
avg.AddFunction(AggregateFunction({LogicalTypeId::DECIMAL}, LogicalTypeId::DECIMAL, nullptr, nullptr, nullptr,
nullptr, nullptr, FunctionNullHandling::DEFAULT_NULL_HANDLING, nullptr,
BindDecimalAvg));
Expand All @@ -291,24 +312,31 @@ AggregateFunctionSet AvgFun::GetFunctions() {
avg.AddFunction(GetAverageAggregate(PhysicalType::INT128));
avg.AddFunction(GetAverageAggregate(PhysicalType::INTERVAL));
avg.AddFunction(AggregateFunction::UnaryAggregate<AvgState<double>, double, double, NumericAverageOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE));
LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetAvgStateType));

avg.AddFunction(AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, int64_t, int64_t, DiscreteAverageOperation>(
LogicalType::TIMESTAMP, LogicalType::TIMESTAMP));
LogicalType::TIMESTAMP, LogicalType::TIMESTAMP)
.SetStructStateExport(GetAvgStateType));
avg.AddFunction(AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, int64_t, int64_t, DiscreteAverageOperation>(
LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP_TZ));
LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP_TZ)
.SetStructStateExport(GetAvgStateType));
avg.AddFunction(AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, int64_t, int64_t, DiscreteAverageOperation>(
LogicalType::TIME, LogicalType::TIME));
LogicalType::TIME, LogicalType::TIME)
.SetStructStateExport(GetAvgStateType));
avg.AddFunction(
AggregateFunction::UnaryAggregate<AvgState<hugeint_t>, dtime_tz_t, dtime_tz_t, TimeTZAverageOperation>(
LogicalType::TIME_TZ, LogicalType::TIME_TZ));
LogicalType::TIME_TZ, LogicalType::TIME_TZ)
.SetStructStateExport(GetAvgStateType));

return avg;
}

AggregateFunction FAvgFun::GetFunction() {
return AggregateFunction::UnaryAggregate<KahanAvgState, double, double, KahanAverageOperation>(LogicalType::DOUBLE,
LogicalType::DOUBLE);
auto function = AggregateFunction::UnaryAggregate<KahanAvgState, double, double, KahanAverageOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetKahanAvgStateType);
return function;
}

} // namespace duckdb
15 changes: 14 additions & 1 deletion src/duckdb/extension/core_functions/aggregate/algebraic/corr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@

namespace duckdb {

LogicalType GetCorrStateType() {
child_list_t<LogicalType> state_children;
state_children.emplace_back("cov_pop", CovarPopFun::GetFunction().GetStateType());
state_children.emplace_back("dev_pop_x", VarPopFun::GetFunction().GetStateType());
state_children.emplace_back("dev_pop_y", VarPopFun::GetFunction().GetStateType());
return LogicalType::STRUCT(std::move(state_children));
}

LogicalType GetCorrExportStateType(const AggregateFunction &) {
return GetCorrStateType();
}

AggregateFunction CorrFun::GetFunction() {
return AggregateFunction::BinaryAggregate<CorrState, double, double, double, CorrOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE);
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetCorrExportStateType);
}
} // namespace duckdb
20 changes: 17 additions & 3 deletions src/duckdb/extension/core_functions/aggregate/algebraic/covar.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#include "core_functions/aggregate/algebraic_functions.hpp"
#include "duckdb/common/types/null_value.hpp"
#include "core_functions/aggregate/algebraic/covar.hpp"

namespace duckdb {

namespace {

LogicalType GetCovarStateType(const AggregateFunction &) {
child_list_t<LogicalType> child_types;
child_types.emplace_back("count", LogicalType::UBIGINT);
child_types.emplace_back("meanx", LogicalType::DOUBLE);
child_types.emplace_back("meany", LogicalType::DOUBLE);
child_types.emplace_back("co_moment", LogicalType::DOUBLE);
return LogicalType::STRUCT(std::move(child_types));
}

} // namespace

AggregateFunction CovarPopFun::GetFunction() {
return AggregateFunction::BinaryAggregate<CovarState, double, double, double, CovarPopOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE);
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetCovarStateType);
}

AggregateFunction CovarSampFun::GetFunction() {
return AggregateFunction::BinaryAggregate<CovarState, double, double, double, CovarSampOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE);
LogicalType::DOUBLE, LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetCovarStateType);
}

} // namespace duckdb
29 changes: 22 additions & 7 deletions src/duckdb/extension/core_functions/aggregate/algebraic/stddev.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
#include "core_functions/aggregate/algebraic_functions.hpp"
#include "duckdb/common/vector_operations/vector_operations.hpp"
#include "duckdb/function/function_set.hpp"
#include "core_functions/aggregate/algebraic/stddev.hpp"
#include <cmath>

namespace duckdb {

namespace {

LogicalType GetStddevStateType(const AggregateFunction &) {
child_list_t<LogicalType> child_types;
child_types.emplace_back("count", LogicalType::UBIGINT);
child_types.emplace_back("mean", LogicalType::DOUBLE);
child_types.emplace_back("dsquared", LogicalType::DOUBLE);
return LogicalType::STRUCT(std::move(child_types));
}

} // namespace

AggregateFunction StdDevSampFun::GetFunction() {
return AggregateFunction::UnaryAggregate<StddevState, double, double, STDDevSampOperation>(LogicalType::DOUBLE,
LogicalType::DOUBLE);
LogicalType::DOUBLE)
.SetStructStateExport(GetStddevStateType);
}

AggregateFunction StdDevPopFun::GetFunction() {
return AggregateFunction::UnaryAggregate<StddevState, double, double, STDDevPopOperation>(LogicalType::DOUBLE,
LogicalType::DOUBLE);
LogicalType::DOUBLE)
.SetStructStateExport(GetStddevStateType);
}

AggregateFunction VarPopFun::GetFunction() {
return AggregateFunction::UnaryAggregate<StddevState, double, double, VarPopOperation>(LogicalType::DOUBLE,
LogicalType::DOUBLE);
LogicalType::DOUBLE)
.SetStructStateExport(GetStddevStateType);
}

AggregateFunction VarSampFun::GetFunction() {
return AggregateFunction::UnaryAggregate<StddevState, double, double, VarSampOperation>(LogicalType::DOUBLE,
LogicalType::DOUBLE);
LogicalType::DOUBLE)
.SetStructStateExport(GetStddevStateType);
}

AggregateFunction StandardErrorOfTheMeanFun::GetFunction() {
return AggregateFunction::UnaryAggregate<StddevState, double, double, StandardErrorOfTheMeanOperation>(
LogicalType::DOUBLE, LogicalType::DOUBLE);
LogicalType::DOUBLE, LogicalType::DOUBLE)
.SetStructStateExport(GetStddevStateType);
}

} // namespace duckdb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "duckdb/common/exception.hpp"
#include "duckdb/common/types/hash.hpp"
#include "duckdb/common/types/hyperloglog.hpp"
#include "core_functions/aggregate/distributive_functions.hpp"
#include "duckdb/function/function_set.hpp"
#include "duckdb/planner/expression/bound_aggregate_expression.hpp"
#include "hyperloglog.hpp"

namespace duckdb {

Expand All @@ -14,7 +10,7 @@ namespace duckdb {
namespace {

struct ApproxDistinctCountState {
HyperLogLog hll;
HyperLogLogP<10> hll;
};

struct ApproxCountDistinctFunction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,57 @@ struct BitState {
T value;
};

template <class T>
LogicalType GetBitStateType(const AggregateFunction &function) {
child_list_t<LogicalType> child_types;
child_types.emplace_back("is_set", LogicalType::BOOLEAN);

LogicalType value_type = function.return_type;
child_types.emplace_back("value", value_type);

return LogicalType::STRUCT(std::move(child_types));
}

LogicalType GetBitStringStateType(const AggregateFunction &function) {
child_list_t<LogicalType> child_types;
child_types.emplace_back("is_set", LogicalType::BOOLEAN);
child_types.emplace_back("value", function.return_type);
return LogicalType::STRUCT(std::move(child_types));
}

template <class OP>
AggregateFunction GetBitfieldUnaryAggregate(LogicalType type) {
switch (type.id()) {
case LogicalTypeId::TINYINT:
return AggregateFunction::UnaryAggregate<BitState<uint8_t>, int8_t, int8_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint8_t>, int8_t, int8_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint8_t>);
case LogicalTypeId::SMALLINT:
return AggregateFunction::UnaryAggregate<BitState<uint16_t>, int16_t, int16_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint16_t>, int16_t, int16_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint16_t>);
case LogicalTypeId::INTEGER:
return AggregateFunction::UnaryAggregate<BitState<uint32_t>, int32_t, int32_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint32_t>, int32_t, int32_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint32_t>);
case LogicalTypeId::BIGINT:
return AggregateFunction::UnaryAggregate<BitState<uint64_t>, int64_t, int64_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint64_t>, int64_t, int64_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint64_t>);
case LogicalTypeId::HUGEINT:
return AggregateFunction::UnaryAggregate<BitState<hugeint_t>, hugeint_t, hugeint_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<hugeint_t>, hugeint_t, hugeint_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<hugeint_t>);
case LogicalTypeId::UTINYINT:
return AggregateFunction::UnaryAggregate<BitState<uint8_t>, uint8_t, uint8_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint8_t>, uint8_t, uint8_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint8_t>);
case LogicalTypeId::USMALLINT:
return AggregateFunction::UnaryAggregate<BitState<uint16_t>, uint16_t, uint16_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint16_t>, uint16_t, uint16_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint16_t>);
case LogicalTypeId::UINTEGER:
return AggregateFunction::UnaryAggregate<BitState<uint32_t>, uint32_t, uint32_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint32_t>, uint32_t, uint32_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint32_t>);
case LogicalTypeId::UBIGINT:
return AggregateFunction::UnaryAggregate<BitState<uint64_t>, uint64_t, uint64_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uint64_t>, uint64_t, uint64_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uint64_t>);
case LogicalTypeId::UHUGEINT:
return AggregateFunction::UnaryAggregate<BitState<uhugeint_t>, uhugeint_t, uhugeint_t, OP>(type, type);
return AggregateFunction::UnaryAggregate<BitState<uhugeint_t>, uhugeint_t, uhugeint_t, OP>(type, type)
.SetStructStateExport(GetBitStateType<uhugeint_t>);
default:
throw InternalException("Unimplemented bitfield type for unary aggregate");
}
Expand Down Expand Up @@ -202,9 +230,11 @@ AggregateFunctionSet BitAndFun::GetFunctions() {
bit_and.AddFunction(GetBitfieldUnaryAggregate<BitAndOperation>(type));
}

bit_and.AddFunction(
auto bit_string_fun =
AggregateFunction::UnaryAggregateDestructor<BitState<string_t>, string_t, string_t, BitStringAndOperation>(
LogicalType::BIT, LogicalType::BIT));
LogicalType::BIT, LogicalType::BIT);
bit_string_fun.SetStructStateExport(GetBitStringStateType);
bit_and.AddFunction(bit_string_fun);
return bit_and;
}

Expand All @@ -213,9 +243,11 @@ AggregateFunctionSet BitOrFun::GetFunctions() {
for (auto &type : LogicalType::Integral()) {
bit_or.AddFunction(GetBitfieldUnaryAggregate<BitOrOperation>(type));
}
bit_or.AddFunction(
auto bit_string_fun =
AggregateFunction::UnaryAggregateDestructor<BitState<string_t>, string_t, string_t, BitStringOrOperation>(
LogicalType::BIT, LogicalType::BIT));
LogicalType::BIT, LogicalType::BIT);
bit_string_fun.SetStructStateExport(GetBitStringStateType);
bit_or.AddFunction(bit_string_fun);
return bit_or;
}

Expand All @@ -224,9 +256,11 @@ AggregateFunctionSet BitXorFun::GetFunctions() {
for (auto &type : LogicalType::Integral()) {
bit_xor.AddFunction(GetBitfieldUnaryAggregate<BitXorOperation>(type));
}
bit_xor.AddFunction(
auto bit_string_fun =
AggregateFunction::UnaryAggregateDestructor<BitState<string_t>, string_t, string_t, BitStringXorOperation>(
LogicalType::BIT, LogicalType::BIT));
LogicalType::BIT, LogicalType::BIT);
bit_string_fun.SetStructStateExport(GetBitStringStateType);
bit_xor.AddFunction(bit_string_fun);
return bit_xor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,29 @@ struct BoolOrFunFunction {
}
};

LogicalType GetBoolAndStateType(const AggregateFunction &function) {
child_list_t<LogicalType> child_types;
child_types.emplace_back("empty", LogicalType::BOOLEAN);
child_types.emplace_back("val", LogicalType::BOOLEAN);
return LogicalType::STRUCT(std::move(child_types));
}

} // namespace

AggregateFunction BoolOrFun::GetFunction() {
auto fun = AggregateFunction::UnaryAggregate<BoolState, bool, bool, BoolOrFunFunction>(
LogicalType(LogicalTypeId::BOOLEAN), LogicalType::BOOLEAN);
fun.SetOrderDependent(AggregateOrderDependent::NOT_ORDER_DEPENDENT);
fun.SetDistinctDependent(AggregateDistinctDependent::NOT_DISTINCT_DEPENDENT);
return fun;
return fun.SetStructStateExport(GetBoolAndStateType);
}

AggregateFunction BoolAndFun::GetFunction() {
auto fun = AggregateFunction::UnaryAggregate<BoolState, bool, bool, BoolAndFunFunction>(
LogicalType(LogicalTypeId::BOOLEAN), LogicalType::BOOLEAN);
fun.SetOrderDependent(AggregateOrderDependent::NOT_ORDER_DEPENDENT);
fun.SetDistinctDependent(AggregateDistinctDependent::NOT_DISTINCT_DEPENDENT);
return fun;
return fun.SetStructStateExport(GetBoolAndStateType);
}

} // namespace duckdb
Loading