Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function signature of approx_distinct(DECIMAL(a_precision,a_scale)) #7905

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions velox/exec/tests/utils/AggregationFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,15 @@ AggregationFuzzer::AggregationFuzzer(
if (!signature->variables().empty()) {
bool skip = false;
std::unordered_set<std::string> typeVariables;
for (auto& [name, variable] : signature->variables()) {
for (auto& [variableName, variable] : signature->variables()) {
if (variable.isIntegerParameter()) {
LOG(WARNING) << "Skipping generic function signature: " << name
<< signature->toString();
skip = true;
break;
}

typeVariables.insert(name);
typeVariables.insert(variableName);
}
if (skip) {
continue;
Expand Down
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()
.integerVariable("a_precision")
.integerVariable("a_scale")
.returnType(returnType)
.intermediateType("varbinary")
.argumentType("DECIMAL(a_precision, a_scale)")
.build());
signatures.push_back(exec::AggregateFunctionSignatureBuilder()
.integerVariable("a_precision")
.integerVariable("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