ISSUES-2786 fix replace asterisk with join query

This commit is contained in:
zhang2014 2018-08-02 12:15:39 +08:00
parent 9ddee9fc21
commit d7cd77640d
15 changed files with 91 additions and 88 deletions

View File

@ -1156,22 +1156,21 @@ void ExpressionAnalyzer::normalizeTreeImpl(
{
if (typeid_cast<ASTAsterisk *>(asts[i].get()))
{
ASTs all_columns;
Names all_columns_name;
if (storage)
{
/// If we select from a table, get only not MATERIALIZED, not ALIAS columns.
for (const auto & name_type : storage->getColumns().ordinary)
all_columns.emplace_back(std::make_shared<ASTIdentifier>(name_type.name));
}
else
{
for (const auto & name_type : source_columns)
all_columns.emplace_back(std::make_shared<ASTIdentifier>(name_type.name));
}
auto columns_name = storage ? storage->getColumns().ordinary.getNames() : source_columns.getNames();
all_columns_name.insert(all_columns_name.begin(), columns_name.begin(), columns_name.end());
NameSet joined_columns;
collectJoinedColumns(joined_columns);
auto columns_from_joined_table = analyzed_join.columns_from_joined_table.getNames();
all_columns_name.insert(all_columns_name.end(), columns_from_joined_table.begin(), columns_from_joined_table.end());
/// HACK: The side effect of calling the `collectJoinedColumns` method, we have to reset it.
analyzed_join = AnalyzedJoin();
asts.erase(asts.begin() + i);
asts.insert(asts.begin() + i, all_columns.begin(), all_columns.end());
for (size_t idx = 0; idx < all_columns_name.size(); idx++)
asts.insert(asts.begin() + idx + i, std::make_shared<ASTIdentifier>(all_columns_name[idx]));
}
}
}

View File

@ -1,10 +1,10 @@
0 0
1 0
2 1
3 0
4 2
5 0
6 3
7 0
8 4
9 0
0 0 0
1 1 0
2 2 1
3 3 0
4 4 2
5 5 0
6 6 3
7 7 0
8 8 4
9 9 0

View File

@ -1,4 +1,4 @@
SELECT *, joined FROM
SELECT * FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
)

View File

@ -1,5 +1,5 @@
0 0
2 1
4 2
6 3
8 4
0 0 0
2 2 1
4 4 2
6 6 3
8 8 4

View File

@ -1,4 +1,4 @@
SELECT *, joined FROM
SELECT * FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
)

View File

@ -1,15 +1,15 @@
0 0
0 1
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 0
6 0
7 0
8 0
9 0
0 0 0
0 0 1
1 1 2
1 1 3
2 2 4
2 2 5
3 3 6
3 3 7
4 4 8
4 4 9
5 5 0
6 6 0
7 7 0
8 8 0
9 9 0

View File

@ -1,4 +1,4 @@
SELECT *, joined FROM
SELECT * FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
)

View File

@ -1,10 +1,10 @@
0 0
0 1
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
0 0 0
0 0 1
1 1 2
1 1 3
2 2 4
2 2 5
3 3 6
3 3 7
4 4 8
4 4 9

View File

@ -1,4 +1,4 @@
SELECT *, joined FROM
SELECT * FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
)

View File

@ -1,15 +1,15 @@
A 0
A 1
B 2
B 3
C 4
C 5
D 6
D 7
E 8
E 9
F 0
G 0
H 0
I 0
J 0
A A 0
A A 1
B B 2
B B 3
C C 4
C C 5
D D 6
D D 7
E E 8
E E 9
F F 0
G G 0
H H 0
I I 0
J J 0

View File

@ -1,4 +1,4 @@
SELECT *, joined FROM
SELECT * FROM
(
SELECT reinterpretAsString(number + reinterpretAsUInt8('A')) AS k FROM system.numbers LIMIT 10
)

View File

@ -1,11 +1,11 @@
0
1
2
3
4
5
6
7
8
9
10
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10

View File

@ -14,10 +14,10 @@
2 facebook.com
1 google.com
2 yandex.ru
1 baidu.com
1 google.com
2 facebook.com
2 yandex.ru
1 baidu.com 1 baidu.com
1 google.com 1 google.com
2 facebook.com 2 facebook.com
2 yandex.ru 2 yandex.ru
1
1
2

View File

@ -0,0 +1,2 @@
1 2
1 2 3 1 4 5

View File

@ -0,0 +1,2 @@
SELECT * FROM (SELECT 1 AS id, 2 AS value);
SELECT * FROM (SELECT 1 AS id, 2 AS value, 3 AS A) ANY INNER JOIN (SELECT 1 AS id, 4 AS values, 5 AS D) USING id;