2019-01-30 12:01:00 +00:00
|
|
|
#include <Interpreters/SubqueryForSet.h>
|
|
|
|
#include <Interpreters/InterpreterSelectWithUnionQuery.h>
|
2020-04-07 09:48:47 +00:00
|
|
|
#include <Interpreters/IJoin.h>
|
2019-09-09 19:43:37 +00:00
|
|
|
#include <Interpreters/MergeJoin.h>
|
2020-02-10 15:50:12 +00:00
|
|
|
#include <Interpreters/ExpressionActions.h>
|
2019-01-30 12:01:00 +00:00
|
|
|
#include <DataStreams/LazyBlockInputStream.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
void SubqueryForSet::makeSource(std::shared_ptr<InterpreterSelectWithUnionQuery> & interpreter,
|
2019-09-04 16:20:02 +00:00
|
|
|
NamesWithAliases && joined_block_aliases_)
|
2019-01-30 12:01:00 +00:00
|
|
|
{
|
2019-09-04 16:20:02 +00:00
|
|
|
joined_block_aliases = std::move(joined_block_aliases_);
|
2020-09-01 13:53:11 +00:00
|
|
|
source = QueryPipeline::getPipe(interpreter->execute().pipeline);
|
2019-01-30 12:01:00 +00:00
|
|
|
|
2020-09-01 13:53:11 +00:00
|
|
|
sample_block = source.getHeader();
|
2019-09-04 16:20:02 +00:00
|
|
|
renameColumns(sample_block);
|
2019-01-30 12:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubqueryForSet::renameColumns(Block & block)
|
|
|
|
{
|
|
|
|
for (const auto & name_with_alias : joined_block_aliases)
|
|
|
|
{
|
|
|
|
if (block.has(name_with_alias.first))
|
|
|
|
{
|
|
|
|
auto pos = block.getPositionByName(name_with_alias.first);
|
|
|
|
auto column = block.getByPosition(pos);
|
|
|
|
block.erase(pos);
|
|
|
|
column.name = name_with_alias.second;
|
|
|
|
block.insert(std::move(column));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 19:43:37 +00:00
|
|
|
void SubqueryForSet::setJoinActions(ExpressionActionsPtr actions)
|
|
|
|
{
|
|
|
|
actions->execute(sample_block);
|
|
|
|
joined_block_actions = actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SubqueryForSet::insertJoinedBlock(Block & block)
|
|
|
|
{
|
|
|
|
renameColumns(block);
|
|
|
|
|
|
|
|
if (joined_block_actions)
|
|
|
|
joined_block_actions->execute(block);
|
|
|
|
|
|
|
|
return join->addJoinedBlock(block);
|
|
|
|
}
|
|
|
|
|
2020-09-01 13:53:11 +00:00
|
|
|
void SubqueryForSet::setTotals(Block totals)
|
2019-09-09 19:43:37 +00:00
|
|
|
{
|
2020-09-01 13:53:11 +00:00
|
|
|
if (join)
|
2020-03-31 10:38:24 +00:00
|
|
|
{
|
|
|
|
renameColumns(totals);
|
|
|
|
join->setTotals(totals);
|
|
|
|
}
|
2019-09-09 19:43:37 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 12:01:00 +00:00
|
|
|
}
|