diff --git a/velox/exec/tests/utils/AggregationFuzzer.cpp b/velox/exec/tests/utils/AggregationFuzzer.cpp index 4fec6ddd27fc..20bfa5697bf5 100644 --- a/velox/exec/tests/utils/AggregationFuzzer.cpp +++ b/velox/exec/tests/utils/AggregationFuzzer.cpp @@ -484,7 +484,7 @@ AggregationFuzzer::AggregationFuzzer( if (!signature->variables().empty()) { bool skip = false; std::unordered_set 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(); @@ -492,7 +492,7 @@ AggregationFuzzer::AggregationFuzzer( break; } - typeVariables.insert(name); + typeVariables.insert(variableName); } if (skip) { continue; diff --git a/velox/functions/prestosql/aggregates/ApproxDistinctAggregate.cpp b/velox/functions/prestosql/aggregates/ApproxDistinctAggregate.cpp index 44ac8b1c1861..68a8fa8d7c48 100644 --- a/velox/functions/prestosql/aggregates/ApproxDistinctAggregate.cpp +++ b/velox/functions/prestosql/aggregates/ApproxDistinctAggregate.cpp @@ -437,6 +437,7 @@ exec::AggregateRegistrationResult registerApproxDistinct( "smallint", "integer", "bigint", + "hugeint", "real", "double", "varchar", @@ -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( diff --git a/velox/functions/prestosql/aggregates/tests/ApproxDistinctTest.cpp b/velox/functions/prestosql/aggregates/tests/ApproxDistinctTest.cpp index 74d56a7b1dc0..0214ffd2d7ab 100644 --- a/velox/functions/prestosql/aggregates/tests/ApproxDistinctTest.cpp +++ b/velox/functions/prestosql/aggregates/tests/ApproxDistinctTest.cpp @@ -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({expectedResult})}); @@ -41,7 +42,9 @@ class ApproxDistinctTest : public AggregationTestBase { {vectors}, {}, {fmt::format("approx_distinct(c0, {})", maxStandardError)}, - {expected}); + {expected}, + {}, + testWithTableScan); testAggregationsWithCompanion( {vectors}, [](auto& /*builder*/) {}, @@ -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({expectedResult})}); - testAggregations({vectors}, {}, {"approx_distinct(c0)"}, {expected}); + testAggregations( + {vectors}, + {}, + {"approx_distinct(c0)"}, + {expected}, + {}, + testWithTableScan); testAggregationsWithCompanion( {vectors}, [](auto& /*builder*/) {}, @@ -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 @@ -304,6 +324,19 @@ TEST_F(ApproxDistinctTest, globalAggAllNulls) { EXPECT_TRUE(readSingleValue(op).isNull()); } +TEST_F(ApproxDistinctTest, hugeInt) { + auto hugeIntValues = + makeFlatVector(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({1, 2, 3}); auto rawInput2 = makeFlatVector(1000, folly::identity);