Skip to content

Commit

Permalink
Velox: tdigest_agg (#12315)
Browse files Browse the repository at this point in the history
Summary:

Add aggregate function tdigest_agg() in Velox

Differential Revision: D69331895
  • Loading branch information
natashasehgal authored and facebook-github-bot committed Feb 14, 2025
1 parent 704aaf7 commit 44c24d2
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 1 deletion.
1 change: 1 addition & 0 deletions velox/functions/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ velox_add_library(
StringEncodingUtils.cpp
SubscriptUtil.cpp
TimeUtils.cpp
TDigest.h
Utf8Utils.cpp)

velox_link_libraries(
Expand Down
4 changes: 4 additions & 0 deletions velox/functions/lib/TDigest.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ void TDigest<A>::mergeDeserialized(
tdigest::detail::read(input, sum);
}
tdigest::detail::read(input, compression);
// If the TDigest is empty, set compression from TDigest being merged.
if (weights_.empty()) {
setCompression(compression);
}
VELOX_CHECK_EQ(compression, compression_);
tdigest::detail::read(input, totalWeight);
int32_t numNew;
Expand Down
1 change: 1 addition & 0 deletions velox/functions/prestosql/aggregates/AggregateNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const char* const kStdDev = "stddev"; // Alias for stddev_samp.
const char* const kStdDevPop = "stddev_pop";
const char* const kStdDevSamp = "stddev_samp";
const char* const kSum = "sum";
const char* const kTDigestAgg = "tdigest_agg";
const char* const kVariance = "variance"; // Alias for var_samp.
const char* const kVarPop = "var_pop";
const char* const kVarSamp = "var_samp";
Expand Down
1 change: 1 addition & 0 deletions velox/functions/prestosql/aggregates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ velox_add_library(
SetAggregates.cpp
SumAggregate.cpp
SumDataSizeForStatsAggregate.cpp
TDigestAggregate.cpp
VarianceAggregates.cpp)

velox_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "velox/functions/prestosql/aggregates/RegisterAggregateFunctions.h"
#include "velox/exec/Aggregate.h"
#include "velox/functions/prestosql/types/JsonType.h"
#include "velox/functions/prestosql/types/TDigestType.h"

namespace facebook::velox::aggregate::prestosql {

Expand Down Expand Up @@ -150,13 +151,18 @@ extern void registerVarianceAggregates(
const std::string& prefix,
bool withCompanionFunctions,
bool overwrite);
extern void registerTDigestAggregate(
const std::string& prefix,
bool withCompanionFunctions,
bool overwrite);

void registerAllAggregateFunctions(
const std::string& prefix,
bool withCompanionFunctions,
bool onlyPrestoSignatures,
bool overwrite) {
registerJsonType();
registerTDigestType();
registerApproxDistinctAggregates(prefix, withCompanionFunctions, overwrite);
registerApproxMostFrequentAggregate(
prefix, withCompanionFunctions, overwrite);
Expand Down Expand Up @@ -194,6 +200,7 @@ void registerAllAggregateFunctions(
registerSetUnionAggregate(prefix, withCompanionFunctions, overwrite);
registerSumAggregate(prefix, withCompanionFunctions, overwrite);
registerVarianceAggregates(prefix, withCompanionFunctions, overwrite);
registerTDigestAggregate(prefix, withCompanionFunctions, overwrite);
}

extern void registerCountDistinctAggregate(
Expand Down
Loading

0 comments on commit 44c24d2

Please sign in to comment.