@@ -4030,6 +4030,64 @@ TEST_F(AggregationTest, destroyAfterPartialInitialization) {
4030
4030
ASSERT_TRUE (agg.destroyCalled );
4031
4031
}
4032
4032
4033
+ DEBUG_ONLY_TEST_F (
4034
+ AggregationTest,
4035
+ uninitializedDistinctAggrWithExternalMemAggrDuringAbort) {
4036
+ const auto createInput =
4037
+ [&](int32_t startKey, uint32_t numGroups, uint32_t numElementsPerGroup) {
4038
+ return makeRowVector ({
4039
+ makeFlatVector<int32_t >([&]() {
4040
+ std::vector<int32_t > keys;
4041
+ for (auto i = 0 ; i < numGroups; ++i) {
4042
+ for (auto j = 0 ; j < numElementsPerGroup; ++j) {
4043
+ keys.push_back (startKey + i);
4044
+ }
4045
+ }
4046
+ return keys;
4047
+ }()),
4048
+ makeFlatVector<int32_t >(
4049
+ numGroups * numElementsPerGroup,
4050
+ [&](auto row) { return startKey; }),
4051
+ });
4052
+ };
4053
+
4054
+ std::vector<RowVectorPtr> inputs;
4055
+ inputs.emplace_back (createInput (0 , 10000 , 10 ));
4056
+ createDuckDbTable (inputs);
4057
+
4058
+ GroupingSet* groupingSet{nullptr };
4059
+
4060
+ std::atomic_bool groupingSetExtracted{false };
4061
+ SCOPED_TESTVALUE_SET (
4062
+ " facebook::velox::exec::GroupingSet::addInputForActiveRows" ,
4063
+ std::function<void (GroupingSet*)>([&](GroupingSet* _groupingSet) {
4064
+ if (!groupingSetExtracted.exchange (true )) {
4065
+ groupingSet = _groupingSet;
4066
+ }
4067
+ }));
4068
+
4069
+ SCOPED_TESTVALUE_SET (
4070
+ " facebook::velox::memory::MemoryPoolImpl::reserveThreadSafe" ,
4071
+ std::function<void (void *)>([&](void * /* unused*/ ) {
4072
+ if (groupingSet == nullptr ) {
4073
+ return ;
4074
+ }
4075
+ if (groupingSet->numRows () > 0 ) {
4076
+ VELOX_FAIL (" Inject allocation failure." );
4077
+ }
4078
+ }));
4079
+
4080
+ auto plan = PlanBuilder ()
4081
+ .values (inputs)
4082
+ .singleAggregation ({" c0" }, {" array_agg(distinct c1)" })
4083
+ .planNode ();
4084
+
4085
+ VELOX_ASSERT_THROW (
4086
+ assertQuery (
4087
+ plan, " SELECT c0, array_agg(distinct c1) FROM tmp GROUP BY c0" ),
4088
+ " Inject allocation failure." );
4089
+ }
4090
+
4033
4091
TEST_F (AggregationTest, nanKeys) {
4034
4092
// Some keys are NaNs.
4035
4093
auto kNaN = std::numeric_limits<double >::quiet_NaN ();
0 commit comments