ISSUES-320 fix rewrite expression for union all

This commit is contained in:
zhang2014 2018-01-21 17:29:55 +08:00
parent 257e973337
commit 054777a5ab
3 changed files with 17 additions and 2 deletions

View File

@ -95,7 +95,8 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names
ASTSelectQuery & head_query = static_cast<ASTSelectQuery &>(*head);
tail = head_query.next_union_all;
interpreter->next_select_in_union_all = std::make_unique<InterpreterSelectQuery>(head, context, to_stage, subquery_depth);
interpreter->next_select_in_union_all = std::make_unique<InterpreterSelectQuery>(
head, context, required_column_names, to_stage, subquery_depth);
interpreter = interpreter->next_select_in_union_all.get();
}
}
@ -118,10 +119,10 @@ void InterpreterSelectQuery::init(const BlockInputStreamPtr & input, const Names
}
else
{
renameColumns();
if (!required_column_names.empty())
rewriteExpressionList(required_column_names);
renameColumns();
basicInit(input);
}
}

View File

@ -0,0 +1,4 @@
test_string 2
test_string 2
test_string
test_string

View File

@ -0,0 +1,10 @@
DROP TABLE IF EXISTS test.test;
CREATE TABLE test.test ( s String, i Int64) ENGINE = Memory;
INSERT INTO test.test VALUES('test_string', 1);
SELECT s, SUM(i*2) AS i FROM test.test GROUP BY s UNION ALL SELECT s, SUM(i*2) AS i FROM test.test GROUP BY s;
SELECT s FROM (SELECT s, SUM(i*2) AS i FROM test.test GROUP BY s UNION ALL SELECT s, SUM(i*2) AS i FROM test.test GROUP BY s);
DROP TABLE IF EXISTS test.test;