ClickHouse/src/Processors/Transforms/CubeTransform.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.9 KiB
C++
Raw Normal View History

2019-03-19 13:36:19 +00:00
#include <Processors/Transforms/CubeTransform.h>
2019-04-08 13:02:19 +00:00
#include <Processors/Transforms/TotalsHavingTransform.h>
#include <Processors/QueryPlan/AggregatingStep.h>
2022-06-30 10:13:58 +00:00
#include "Processors/Transforms/RollupTransform.h"
2019-03-19 13:36:19 +00:00
namespace DB
{
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
2019-03-19 13:36:19 +00:00
CubeTransform::CubeTransform(Block header, AggregatingTransformParamsPtr params_, bool use_nulls_)
: GroupByModifierTransform(std::move(header), params_, use_nulls_)
, aggregates_mask(getAggregatesMask(params->getHeader(), params->params.aggregates))
2019-03-19 13:36:19 +00:00
{
if (keys.size() >= 8 * sizeof(mask))
throw Exception("Too many keys are used for CubeTransform.", ErrorCodes::LOGICAL_ERROR);
}
Chunk CubeTransform::generate()
{
2019-08-22 09:28:23 +00:00
if (!consumed_chunks.empty())
{
2022-06-30 10:13:58 +00:00
mergeConsumed();
2019-08-22 09:28:23 +00:00
2022-06-30 10:13:58 +00:00
auto num_rows = current_chunk.getNumRows();
mask = (static_cast<UInt64>(1) << keys.size()) - 1;
2019-08-22 09:28:23 +00:00
2022-06-30 10:13:58 +00:00
current_columns = current_chunk.getColumns();
2019-08-22 09:28:23 +00:00
current_zero_columns.clear();
current_zero_columns.reserve(keys.size());
for (auto key : keys)
2022-06-30 10:13:58 +00:00
current_zero_columns.emplace_back(getColumnWithDefaults(key, num_rows));
2019-08-22 09:28:23 +00:00
}
2022-06-30 10:13:58 +00:00
auto gen_chunk = std::move(current_chunk);
2019-03-19 13:36:19 +00:00
if (mask)
{
--mask;
auto columns = current_columns;
2019-04-18 17:28:55 +00:00
auto size = keys.size();
for (size_t i = 0; i < size; ++i)
/// Reverse bit order to support previous behaviour.
2019-04-18 17:32:01 +00:00
if ((mask & (UInt64(1) << (size - i - 1))) == 0)
2019-04-18 12:09:03 +00:00
columns[keys[i]] = current_zero_columns[i];
2019-03-19 13:36:19 +00:00
2019-08-22 09:28:23 +00:00
Chunks chunks;
chunks.emplace_back(std::move(columns), current_columns.front()->size());
current_chunk = merge(std::move(chunks), !use_nulls, false);
2019-03-19 13:36:19 +00:00
}
finalizeChunk(gen_chunk, aggregates_mask);
if (!gen_chunk.empty())
gen_chunk.addColumn(0, ColumnUInt64::create(gen_chunk.getNumRows(), grouping_set++));
2019-04-08 13:02:19 +00:00
return gen_chunk;
2019-03-19 13:36:19 +00:00
}
}