Skip to content

Commit

Permalink
Back out "Back out "[velox][PR] Add support for decimals in approx_di…
Browse files Browse the repository at this point in the history
…stinct aggregate function"" (facebookincubator#7904)

Summary: Pull Request resolved: facebookincubator#7904

Differential Revision: D51913350
  • Loading branch information
kagamiori authored and facebook-github-bot committed Dec 6, 2023
1 parent e963545 commit 80d266c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
16 changes: 16 additions & 0 deletions velox/functions/prestosql/aggregates/ApproxDistinctAggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ exec::AggregateRegistrationResult registerApproxDistinct(
"smallint",
"integer",
"bigint",
"hugeint",
"real",
"double",
"varchar",
Expand All @@ -455,6 +456,21 @@ exec::AggregateRegistrationResult registerApproxDistinct(
.argumentType("double")
.build());
}
signatures.push_back(exec::AggregateFunctionSignatureBuilder()
.typeVariable("a_precision")
.typeVariable("a_scale")
.returnType(returnType)
.intermediateType("varbinary")
.argumentType("DECIMAL(a_precision, a_scale)")
.build());
signatures.push_back(exec::AggregateFunctionSignatureBuilder()
.typeVariable("a_precision")
.typeVariable("a_scale")
.returnType(returnType)
.intermediateType("varbinary")
.argumentType("DECIMAL(a_precision, a_scale)")
.argumentType("double")
.build());
}

return exec::registerAggregateFunction(
Expand Down
45 changes: 39 additions & 6 deletions velox/functions/prestosql/aggregates/tests/ApproxDistinctTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ApproxDistinctTest : public AggregationTestBase {
void testGlobalAgg(
const VectorPtr& values,
double maxStandardError,
int64_t expectedResult) {
int64_t expectedResult,
bool testWithTableScan = true) {
auto vectors = makeRowVector({values});
auto expected =
makeRowVector({makeNullableFlatVector<int64_t>({expectedResult})});
Expand All @@ -41,7 +42,9 @@ class ApproxDistinctTest : public AggregationTestBase {
{vectors},
{},
{fmt::format("approx_distinct(c0, {})", maxStandardError)},
{expected});
{expected},
{},
testWithTableScan);
testAggregationsWithCompanion(
{vectors},
[](auto& /*builder*/) {},
Expand All @@ -56,15 +59,26 @@ class ApproxDistinctTest : public AggregationTestBase {
{},
{fmt::format("approx_set(c0, {})", maxStandardError)},
{"cardinality(a0)"},
{expected});
{expected},
{},
testWithTableScan);
}

void testGlobalAgg(const VectorPtr& values, int64_t expectedResult) {
void testGlobalAgg(
const VectorPtr& values,
int64_t expectedResult,
bool testWithTableScan = true) {
auto vectors = makeRowVector({values});
auto expected =
makeRowVector({makeNullableFlatVector<int64_t>({expectedResult})});

testAggregations({vectors}, {}, {"approx_distinct(c0)"}, {expected});
testAggregations(
{vectors},
{},
{"approx_distinct(c0)"},
{expected},
{},
testWithTableScan);
testAggregationsWithCompanion(
{vectors},
[](auto& /*builder*/) {},
Expand All @@ -75,7 +89,13 @@ class ApproxDistinctTest : public AggregationTestBase {
{expected});

testAggregations(
{vectors}, {}, {"approx_set(c0)"}, {"cardinality(a0)"}, {expected});
{vectors},
{},
{"approx_set(c0)"},
{"cardinality(a0)"},
{expected},
{},
testWithTableScan);
}

template <typename T, typename U>
Expand Down Expand Up @@ -304,6 +324,19 @@ TEST_F(ApproxDistinctTest, globalAggAllNulls) {
EXPECT_TRUE(readSingleValue(op).isNull());
}

TEST_F(ApproxDistinctTest, hugeInt) {
auto hugeIntValues =
makeFlatVector<int128_t>(50000, [](auto row) { return row; });
// Last param is set false to disable tablescan test
// as DWRF writer doesn't have hugeint support.
// Refer:https://github.com/facebookincubator/velox/issues/7775
testGlobalAgg(hugeIntValues, 49669, false);
testGlobalAgg(
hugeIntValues, common::hll::kLowestMaxStandardError, 50110, false);
testGlobalAgg(
hugeIntValues, common::hll::kHighestMaxStandardError, 41741, false);
}

TEST_F(ApproxDistinctTest, streaming) {
auto rawInput1 = makeFlatVector<int64_t>({1, 2, 3});
auto rawInput2 = makeFlatVector<int64_t>(1000, folly::identity);
Expand Down

0 comments on commit 80d266c

Please sign in to comment.