Skip to content

Commit 870d7d5

Browse files
authored
fix the problem of multishard incorrect result on distinct (#831)
* fix the problem of multishard incorrect result on distinct * code revise
1 parent 08b849f commit 870d7d5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/AggregateFunctions/Streaming/AggregateFunctionDistinct.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ struct AggregateFunctionDistinctSingleNumericData
107107
for (auto it = extra_data_since_last_finalize.begin(); it != extra_data_since_last_finalize.end();)
108108
{
109109
if (rhs.set.find(*it) != rhs.set.end())
110-
it = extra_data_since_last_finalize.erase(it);
110+
{
111+
bool is_new_data = std::find(rhs.extra_data_since_last_finalize.begin(), rhs.extra_data_since_last_finalize.end(), *it)
112+
!= rhs.extra_data_since_last_finalize.end();
113+
if (is_new_data)
114+
++it;
115+
else
116+
it = extra_data_since_last_finalize.erase(it);
117+
}
111118
else
119+
{
112120
++it;
121+
}
113122
}
114123

115124
/// Merge and deduplicate rhs' extra data
@@ -176,9 +185,18 @@ struct AggregateFunctionDistinctGenericData
176185
for (auto next = extra_data_since_last_finalize.begin(); next != extra_data_since_last_finalize.end();)
177186
{
178187
if (rhs.set.find(*next) != rhs.set.end())
179-
next = extra_data_since_last_finalize.erase(next);
188+
{
189+
bool is_new_data = std::find(rhs.extra_data_since_last_finalize.begin(), rhs.extra_data_since_last_finalize.end(), *next)
190+
!= rhs.extra_data_since_last_finalize.end();
191+
if (is_new_data)
192+
++next;
193+
else
194+
next = extra_data_since_last_finalize.erase(next);
195+
}
180196
else
197+
{
181198
++next;
199+
}
182200
}
183201

184202
/// Merge and deduplicate rhs' extra data

tests/stream/test_stream_smoke/0012_multishards7.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,14 @@ tests:
606606
query_type: table
607607
depends_on: '1366'
608608
wait: 1
609-
query: insert into test13_multishard_7(id, val) values(1, 30), (2, 40), (3, 60)
609+
query: insert into test13_multishard_7(id, val) values(1, 40), (1, 30)
610610

611611
- client: python
612612
query_type: table
613613
kill: '1366'
614614
kill_wait: 2
615615
wait: 1
616-
query: insert into test13_multishard_7(id, val) values(1, 30), (1, 40), (1, 60), (2, 40), (3, 40)
616+
query: insert into test13_multishard_7(id, val) values(1, 30), (1, 50), (2, 50), (3, 50)
617617

618618
- client: python
619619
query_type: table
@@ -624,5 +624,5 @@ tests:
624624
expected_results:
625625
- query_id: '1366'
626626
expected_results:
627-
- [130, 130]
628-
- [130, 340]
627+
- [70, 70]
628+
- [120, 250]

0 commit comments

Comments
 (0)