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>
|
2019-03-19 13:36:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
CubeTransform::CubeTransform(Block header, AggregatingTransformParamsPtr params_)
|
|
|
|
: IInflatingTransform(std::move(header), params_->getHeader())
|
|
|
|
, params(std::move(params_))
|
|
|
|
, keys(params->params.keys)
|
|
|
|
{
|
|
|
|
if (keys.size() >= 8 * sizeof(mask))
|
|
|
|
throw Exception("Too many keys are used for CubeTransform.", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CubeTransform::consume(Chunk chunk)
|
|
|
|
{
|
|
|
|
consumed_chunk = std::move(chunk);
|
|
|
|
auto num_rows = current_chunk.getNumRows();
|
|
|
|
mask = (UInt64(1) << keys.size()) - 1;
|
|
|
|
|
|
|
|
current_columns = consumed_chunk.getColumns();
|
|
|
|
current_zero_columns.clear();
|
2019-04-18 12:09:03 +00:00
|
|
|
current_zero_columns.reserve(keys.size());
|
2019-03-19 13:36:19 +00:00
|
|
|
|
2019-04-18 12:09:03 +00:00
|
|
|
for (auto key : keys)
|
|
|
|
current_zero_columns.emplace_back(current_columns[key]->cloneEmpty()->cloneResized(num_rows));
|
2019-03-19 13:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CubeTransform::canGenerate()
|
|
|
|
{
|
|
|
|
return consumed_chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
Chunk CubeTransform::generate()
|
|
|
|
{
|
|
|
|
auto gen_chunk = std::move(consumed_chunk);
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
|
|
|
--mask;
|
2019-04-18 16:27:10 +00:00
|
|
|
consumed_chunk = gen_chunk;
|
2019-03-19 13:36:19 +00:00
|
|
|
|
|
|
|
auto columns = current_columns;
|
2019-04-18 12:09:03 +00:00
|
|
|
for (size_t i = 0; i < keys.size(); ++i)
|
2019-03-19 13:36:19 +00:00
|
|
|
if (mask & (UInt64(1) << i))
|
2019-04-18 12:09:03 +00:00
|
|
|
columns[keys[i]] = current_zero_columns[i];
|
2019-03-19 13:36:19 +00:00
|
|
|
|
|
|
|
BlocksList cube_blocks = { getInputPort().getHeader().cloneWithColumns(columns) };
|
|
|
|
auto cube_block = params->aggregator.mergeBlocks(cube_blocks, false);
|
|
|
|
|
|
|
|
auto num_rows = cube_block.rows();
|
2019-04-18 16:27:10 +00:00
|
|
|
gen_chunk = Chunk(cube_block.getColumns(), num_rows);
|
2019-03-19 13:36:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 13:02:19 +00:00
|
|
|
finalizeChunk(gen_chunk);
|
|
|
|
return gen_chunk;
|
2019-03-19 13:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|