Fixing tests.

This commit is contained in:
Nikolai Kochetov 2024-09-17 12:50:26 +00:00
parent 5f6d95da20
commit 83a5ccd312
3 changed files with 26 additions and 29 deletions

View File

@ -6,6 +6,7 @@
#include <Processors/Transforms/MergingAggregatedMemoryEfficientTransform.h>
#include <Processors/Transforms/MergingAggregatedTransform.h>
#include <QueryPipeline/QueryPipelineBuilder.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -41,7 +42,6 @@ MergingAggregatedStep::MergingAggregatedStep(
bool should_produce_results_in_order_of_bucket_number_,
size_t max_block_size_,
size_t memory_bound_merging_max_block_bytes_,
SortDescription group_by_sort_description_,
bool memory_bound_merging_of_aggregation_results_enabled_)
: ITransformingStep(
input_stream_,
@ -55,13 +55,12 @@ MergingAggregatedStep::MergingAggregatedStep(
, memory_efficient_merge_threads(memory_efficient_merge_threads_)
, max_block_size(max_block_size_)
, memory_bound_merging_max_block_bytes(memory_bound_merging_max_block_bytes_)
, group_by_sort_description(std::move(group_by_sort_description_))
, should_produce_results_in_order_of_bucket_number(should_produce_results_in_order_of_bucket_number_)
, memory_bound_merging_of_aggregation_results_enabled(memory_bound_merging_of_aggregation_results_enabled_)
{
}
void MergingAggregatedStep::applyOrder(SortDescription input_sort_description) ///, DataStream::SortScope sort_scope)
void MergingAggregatedStep::applyOrder(SortDescription input_sort_description)
{
/// Columns might be reordered during optimization, so we better to update sort description.
group_by_sort_description = std::move(input_sort_description);
@ -132,11 +131,18 @@ void MergingAggregatedStep::transformPipeline(QueryPipelineBuilder & pipeline, c
void MergingAggregatedStep::describeActions(FormatSettings & settings) const
{
params.explain(settings.out, settings.offset);
if (!group_by_sort_description.empty())
{
String prefix(settings.offset, settings.indent_char);
settings.out << prefix << "Order: " << dumpSortDescription(group_by_sort_description) << '\n';
}
}
void MergingAggregatedStep::describeActions(JSONBuilder::JSONMap & map) const
{
params.explain(map);
if (!group_by_sort_description.empty())
map.add("Order", dumpSortDescription(group_by_sort_description));
}
void MergingAggregatedStep::updateOutputStream()
@ -153,7 +159,7 @@ bool MergingAggregatedStep::memoryBoundMergingWillBeUsed() const
const SortDescription & MergingAggregatedStep::getSortDescription() const
{
if (memoryBoundMergingWillBeUsed())
if (memoryBoundMergingWillBeUsed() && should_produce_results_in_order_of_bucket_number)
return group_by_sort_description;
return IQueryPlanStep::getSortDescription();

View File

@ -1,30 +1,27 @@
0
8
6
4
10
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
30
16
32
24
22
20
26
34
sort properties are reused after MergingAggregated
Sorting
Sorting: x ASC
Prefix sort description: x ASC
Result sort description: x ASC
Sort description: x ASC
MergingAggregated
Sorting: x ASC
Aggregates:
Aggregating
Sorting: x ASC
@ -51,12 +48,10 @@ Sorting: x ASC
4
2
0
choosing of sort order is not working
Sorting
Sorting: x DESC
Sort description: x DESC
MergingAggregated
Sorting: x ASC
Aggregates:
Aggregating
Sorting: x ASC
@ -83,13 +78,10 @@ Sorting: x ASC
34
36
38
finish sorting is used
Sorting
Sorting: x ASC, sum(y) ASC
Prefix sort description: x ASC
Result sort description: x ASC, sum(y) ASC
Sort description: x ASC, sum(y) ASC
MergingAggregated
Sorting: x ASC
Aggregates:
Aggregating
Sorting: x ASC

View File

@ -9,14 +9,13 @@ set optimize_aggregation_in_order=1;
set enable_memory_bound_merging_of_aggregation_results=1;
set prefer_localhost_replica=1;
-- Nothing is working here :(
select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x;
select 'sort properties are reused after MergingAggregated';
select replaceAll(trimLeft(explain), '__table1.', '') from (explain actions = 1, sorting=1, description=0 select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x) where explain ilike '%sort%' or explain like '%ReadFromMergeTree%' or explain like '%Aggregat%';
select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x desc;
select 'choosing of sort order is not working';
select replaceAll(trimLeft(explain), '__table1.', '') from (explain actions = 1, sorting=1, description=0 select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x desc ) where explain ilike '%sort%' or explain like '%ReadFromMergeTree%' or explain like '%Aggregat%';
select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x, s;
select 'finish sorting is used';
select replaceAll(trimLeft(explain), '__table1.', '') from (explain actions = 1, sorting=1, description=0 select sum(y) as s from remote('127.0.0.{1,2}', currentDatabase(), tab) group by x order by x, s) where explain ilike '%sort%' or explain like '%ReadFromMergeTree%' or explain like '%Aggregat%';