mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Backport #68950 to 24.7: Fix possible wrong result during anyHeavy state merge
This commit is contained in:
parent
b4298a71b8
commit
f57d5850b2
@ -68,7 +68,10 @@ public:
|
|||||||
if (data().isEqualTo(to.data()))
|
if (data().isEqualTo(to.data()))
|
||||||
counter += to.counter;
|
counter += to.counter;
|
||||||
else if (!data().has() || counter < to.counter)
|
else if (!data().has() || counter < to.counter)
|
||||||
|
{
|
||||||
data().set(to.data(), arena);
|
data().set(to.data(), arena);
|
||||||
|
counter = to.counter - counter;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
counter -= to.counter;
|
counter -= to.counter;
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,11 @@ def test_aggregate_states(start_cluster):
|
|||||||
f"select hex(initializeAggregation('{function_name}State', 'foo'))"
|
f"select hex(initializeAggregation('{function_name}State', 'foo'))"
|
||||||
).strip()
|
).strip()
|
||||||
|
|
||||||
|
def get_final_value_unhex(node, function_name, value):
|
||||||
|
return node.query(
|
||||||
|
f"select finalizeAggregation(unhex('{value}')::AggregateFunction({function_name}, String))"
|
||||||
|
).strip()
|
||||||
|
|
||||||
for aggregate_function in aggregate_functions:
|
for aggregate_function in aggregate_functions:
|
||||||
logging.info("Checking %s", aggregate_function)
|
logging.info("Checking %s", aggregate_function)
|
||||||
|
|
||||||
@ -95,7 +100,33 @@ def test_aggregate_states(start_cluster):
|
|||||||
|
|
||||||
upstream_state = get_aggregate_state_hex(upstream, aggregate_function)
|
upstream_state = get_aggregate_state_hex(upstream, aggregate_function)
|
||||||
if upstream_state != backward_state:
|
if upstream_state != backward_state:
|
||||||
|
allowed_changes_if_result_is_the_same = ["anyHeavy"]
|
||||||
|
|
||||||
|
if aggregate_function in allowed_changes_if_result_is_the_same:
|
||||||
|
backward_final_from_upstream = get_final_value_unhex(
|
||||||
|
backward, aggregate_function, upstream_state
|
||||||
|
)
|
||||||
|
upstream_final_from_backward = get_final_value_unhex(
|
||||||
|
upstream, aggregate_function, backward_state
|
||||||
|
)
|
||||||
|
|
||||||
|
if backward_final_from_upstream == upstream_final_from_backward:
|
||||||
logging.info(
|
logging.info(
|
||||||
|
"OK %s (but different intermediate states)", aggregate_function
|
||||||
|
)
|
||||||
|
passed += 1
|
||||||
|
else:
|
||||||
|
logging.error(
|
||||||
|
"Failed %s, Intermediate: %s (backward) != %s (upstream). Final from intermediate: %s (backward from upstream state) != %s (upstream from backward state)",
|
||||||
|
aggregate_function,
|
||||||
|
backward_state,
|
||||||
|
upstream_state,
|
||||||
|
backward_final_from_upstream,
|
||||||
|
upstream_final_from_backward,
|
||||||
|
)
|
||||||
|
failed += 1
|
||||||
|
else:
|
||||||
|
logging.error(
|
||||||
"Failed %s, %s (backward) != %s (upstream)",
|
"Failed %s, %s (backward) != %s (upstream)",
|
||||||
aggregate_function,
|
aggregate_function,
|
||||||
backward_state,
|
backward_state,
|
||||||
|
1
tests/queries/0_stateless/03230_anyHeavy_merge.reference
Normal file
1
tests/queries/0_stateless/03230_anyHeavy_merge.reference
Normal file
@ -0,0 +1 @@
|
|||||||
|
a
|
4
tests/queries/0_stateless/03230_anyHeavy_merge.sql
Normal file
4
tests/queries/0_stateless/03230_anyHeavy_merge.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
DROP TABLE IF EXISTS t;
|
||||||
|
CREATE TABLE t (letter String) ENGINE=MergeTree order by () partition by letter;
|
||||||
|
INSERT INTO t VALUES ('a'), ('a'), ('a'), ('a'), ('b'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('c');
|
||||||
|
SELECT anyHeavy(if(letter != 'b', letter, NULL)) FROM t;
|
Loading…
Reference in New Issue
Block a user