Push actions result to begin of block.

This commit is contained in:
Nikolai Kochetov 2021-01-19 00:54:01 +03:00
parent c00471bd1c
commit b9c0f2b4c9
3 changed files with 14 additions and 4 deletions

View File

@ -692,7 +692,7 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second)
{
/// first: x (1), x (2), y ==> x (2), z, x (3)
/// second: x (1), x (2), x (3) ==> x (3), x (2), x (1)
/// merge: x (1), x (2), x (3), y =(first)=> x (3), y, x (2), z, x (4) =(second)=> y, z, x (4), x (2), x (3)
/// merge: x (1), x (2), x (3), y =(first)=> x (2), z, x (4), x (3) =(second)=> x (3), x (4), x (2), z
/// Will store merged result in `first`.
@ -775,8 +775,8 @@ ActionsDAGPtr ActionsDAG::merge(ActionsDAG && first, ActionsDAG && second)
}
}
for (auto * node : second.index)
first.index.insert(node);
for (auto it = second.index.rbegin(); it != second.index.rend(); ++it)
first.index.prepend(*it);
}

View File

@ -106,6 +106,8 @@ public:
std::list<Node *>::iterator end() { return list.end(); }
std::list<Node *>::const_iterator begin() const { return list.begin(); }
std::list<Node *>::const_iterator end() const { return list.end(); }
std::list<Node *>::const_reverse_iterator rbegin() const { return list.rbegin(); }
std::list<Node *>::const_reverse_iterator rend() const { return list.rend(); }
std::list<Node *>::const_iterator find(std::string_view key) const
{
auto it = map.find(key);
@ -119,6 +121,7 @@ public:
/// If node with the same name exists, it is removed from map, but not list.
/// It is expected and used for project(), when result may have several columns with the same name.
void insert(Node * node) { map[node->result_name] = list.emplace(list.end(), node); }
void prepend(Node * node) { map[node->result_name] = list.emplace(list.begin(), node); }
/// If node with same name exists in index, replace it. Otherwise insert new node to index.
void replace(Node * node)

View File

@ -472,9 +472,16 @@ void ExpressionActions::execute(Block & block, size_t & num_rows, bool dry_run)
block.erase(input);
}
Block res;
for (auto pos : result_positions)
if (execution_context.columns[pos].column)
block.insert(execution_context.columns[pos]);
res.insert(execution_context.columns[pos]);
for (const auto & item : block)
res.insert(std::move(item));
block.swap(res);
num_rows = execution_context.num_rows;
}