mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
small changes(revert)
This commit is contained in:
parent
6ad6d6a121
commit
76b43a6aba
@ -2245,19 +2245,17 @@ void QueryAnalyzer::validateJoinTableExpressionWithoutAlias(const QueryTreeNodeP
|
||||
if (table_expression_has_alias)
|
||||
return;
|
||||
|
||||
if (join_node->as<JoinNode &>().getKind() == JoinKind::Paste)
|
||||
return;
|
||||
|
||||
auto * query_node = table_expression_node->as<QueryNode>();
|
||||
auto * union_node = table_expression_node->as<UnionNode>();
|
||||
if ((query_node && !query_node->getCTEName().empty()) || (union_node && !union_node->getCTEName().empty()))
|
||||
return;
|
||||
|
||||
auto table_expression_node_type = table_expression_node->getNodeType();
|
||||
auto * join_typed = join_node->as<JoinNode>();
|
||||
if (table_expression_node_type == QueryTreeNodeType::QUERY && join_typed->getKind() == JoinKind::Paste)
|
||||
{
|
||||
checkDuplicateTableNamesOrAlias(join_node, join_typed->getLeftTableExpression(), join_typed->getRightTableExpression(), scope);
|
||||
return;
|
||||
}
|
||||
else if (table_expression_node_type == QueryTreeNodeType::TABLE_FUNCTION ||
|
||||
|
||||
if (table_expression_node_type == QueryTreeNodeType::TABLE_FUNCTION ||
|
||||
table_expression_node_type == QueryTreeNodeType::QUERY ||
|
||||
table_expression_node_type == QueryTreeNodeType::UNION)
|
||||
throw Exception(ErrorCodes::ALIAS_REQUIRED,
|
||||
@ -6797,6 +6795,9 @@ void QueryAnalyzer::checkDuplicateTableNamesOrAlias(const QueryTreeNodePtr & joi
|
||||
auto * left_node = left_table_expr->as<QueryNode>();
|
||||
auto * right_node = right_table_expr->as<QueryNode>();
|
||||
|
||||
if (!left_node && !right_node)
|
||||
return;
|
||||
|
||||
if (left_node)
|
||||
for (const auto & name_and_type : left_node->getProjectionColumns())
|
||||
column_names.push_back(name_and_type.name);
|
||||
@ -6811,7 +6812,7 @@ void QueryAnalyzer::checkDuplicateTableNamesOrAlias(const QueryTreeNodePtr & joi
|
||||
for (size_t i = 0; i < column_names.size() - 1; i++) // Check if there is no any duplicates because it will lead to broken result
|
||||
if (column_names[i] == column_names[i+1])
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"Name of columns and aliases should be unique for this query (you can add/change aliases so they will not be duplicated)"
|
||||
"Name of columns and aliases should be unique for this query (you can add/change aliases to avoid duplication)"
|
||||
"While processing '{}'", join_node->formatASTForErrorMessage());
|
||||
}
|
||||
|
||||
@ -6826,6 +6827,9 @@ void QueryAnalyzer::resolveJoin(QueryTreeNodePtr & join_node, IdentifierResolveS
|
||||
resolveQueryJoinTreeNode(join_node_typed.getRightTableExpression(), scope, expressions_visitor);
|
||||
validateJoinTableExpressionWithoutAlias(join_node, join_node_typed.getRightTableExpression(), scope);
|
||||
|
||||
if (!join_node_typed.getLeftTableExpression()->hasAlias() && !join_node_typed.getRightTableExpression()->hasAlias())
|
||||
checkDuplicateTableNamesOrAlias(join_node, join_node_typed.getLeftTableExpression(), join_node_typed.getRightTableExpression(), scope);
|
||||
|
||||
if (join_node_typed.isOnJoinExpression())
|
||||
{
|
||||
expressions_visitor.visit(join_node_typed.getJoinExpression());
|
||||
|
@ -101,3 +101,7 @@ UInt64
|
||||
4 4
|
||||
5 5
|
||||
1 2 3
|
||||
0 0
|
||||
1 1
|
||||
0
|
||||
1
|
||||
|
@ -43,3 +43,13 @@ SELECT * FROM (SELECT number FROM test PASTE JOIN (Select number FROM numbers(7)
|
||||
SELECT * FROM (SELECT number FROM test PASTE JOIN (SELECT number FROM test PASTE JOIN (Select number FROM numbers(7)))) PASTE JOIN (SELECT number FROM numbers(6) PASTE JOIN (SELECT number FROM test)) SETTINGS joined_subquery_requires_alias = 0;
|
||||
SELECT * FROM (SELECT 1 AS a) PASTE JOIN (SELECT 2 AS b) PASTE JOIN (SELECT 3 AS c) SETTINGS allow_experimental_analyzer = 1;
|
||||
SELECT * FROM (SELECT 1 AS a) PASTE JOIN (SELECT 2 AS b) PASTE JOIN (SELECT 3 AS a) SETTINGS allow_experimental_analyzer = 1; -- { serverError AMBIGUOUS_COLUMN_NAME }
|
||||
|
||||
SET allow_experimental_analyzer = 1;
|
||||
CREATE TABLE test1 (a Int32) engine=MergeTree order by a;
|
||||
INSERT INTO test1 SELECT * FROM numbers(2);
|
||||
CREATE TABLE test2 (a Int32) engine=MergeTree order by a;
|
||||
INSERT INTO test2 SELECT * FROM numbers(2);
|
||||
SELECT * FROM test1 PASTE JOIN (SELECT * FROM test2);
|
||||
SELECT a `test2.a` FROM test1 PASTE JOIN test2;
|
||||
SELECT * FROM test1 `test2.a` PASTE JOIN test2 `test2.a`; -- { serverError MULTIPLE_EXPRESSIONS_FOR_ALIAS }
|
||||
SELECT * FROM test1 PASTE JOIN (SELECT number AS a FROM numbers(2) ORDER BY number DESC); -- { serverError AMBIGUOUS_COLUMN_NAME }
|
||||
|
Loading…
Reference in New Issue
Block a user