errors fix

This commit is contained in:
yariks5s 2024-01-10 15:16:53 +00:00
parent d1f00b5b22
commit f656a6d799
2 changed files with 7 additions and 5 deletions

View File

@ -6791,13 +6791,13 @@ void QueryAnalyzer::checkDuplicateTableNamesOrAlias(QueryTreeNodePtr & join_node
column_names.push_back(name_and_type.name); column_names.push_back(name_and_type.name);
if (column_names.empty()) if (column_names.empty())
return; throw Exception(ErrorCodes::LOGICAL_ERROR, "Names of projection columns cannot be empty");
std::sort(column_names.begin(), column_names.end()); std::sort(column_names.begin(), column_names.end());
for (size_t i = 0; i < column_names.size() - 1; i++) // Check if there is not any duplicates because it will lead to broken result for (size_t i = 0; i < column_names.size() - 1; i++) // Check if there is not any duplicates because it will lead to broken result
if (column_names[i] == column_names[i+1]) if (column_names[i] == column_names[i+1])
throw Exception(ErrorCodes::BAD_ARGUMENTS, throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Name of columns and aliases should be unique for this query (you can add alias that will be different)" "Name of columns and aliases should be unique for this query (you can add/change aliases so they will not be duplicated)"
"While processing '{}'", join_node->formatASTForErrorMessage()); "While processing '{}'", join_node->formatASTForErrorMessage());
} }
@ -6812,7 +6812,8 @@ void QueryAnalyzer::resolveJoin(QueryTreeNodePtr & join_node, IdentifierResolveS
resolveQueryJoinTreeNode(join_node_typed.getRightTableExpression(), scope, expressions_visitor); resolveQueryJoinTreeNode(join_node_typed.getRightTableExpression(), scope, expressions_visitor);
validateJoinTableExpressionWithoutAlias(join_node, join_node_typed.getRightTableExpression(), scope); validateJoinTableExpressionWithoutAlias(join_node, join_node_typed.getRightTableExpression(), scope);
checkDuplicateTableNamesOrAlias(join_node, join_node_typed.getLeftTableExpression(), join_node_typed.getRightTableExpression()); if (!join_node_typed.getLeftTableExpression()->hasAlias() && !join_node_typed.getRightTableExpression()->hasAlias())
checkDuplicateTableNamesOrAlias(join_node, join_node_typed.getLeftTableExpression(), join_node_typed.getRightTableExpression());
if (join_node_typed.isOnJoinExpression()) if (join_node_typed.isOnJoinExpression())
{ {

View File

@ -24,6 +24,7 @@
#include <Storages/StorageDictionary.h> #include <Storages/StorageDictionary.h>
#include <Storages/StorageJoin.h> #include <Storages/StorageJoin.h>
#include <Storages/StorageValues.h> #include <Storages/StorageValues.h>
#include "Common/Exception.h"
namespace DB namespace DB
{ {
@ -267,13 +268,13 @@ bool JoinedTables::resolveTables()
for (auto & name : t.columns.getNames()) for (auto & name : t.columns.getNames())
column_names.push_back(name); column_names.push_back(name);
if (column_names.empty()) if (column_names.empty())
return false; throw Exception(ErrorCodes::LOGICAL_ERROR, "Names of joining columns cannot be empty");
std::sort(column_names.begin(), column_names.end()); std::sort(column_names.begin(), column_names.end());
for (size_t i = 0; i < column_names.size() - 1; i++) // Check if there is not any duplicates because it will lead to broken result for (size_t i = 0; i < column_names.size() - 1; i++) // Check if there is not any duplicates because it will lead to broken result
if (column_names[i] == column_names[i+1]) if (column_names[i] == column_names[i+1])
throw Exception(ErrorCodes::BAD_ARGUMENTS, throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Name of columns and aliases should be unique for this query (you can add alias that will be different)" "Name of columns and aliases should be unique for this query (you can add/change aliases so they will not be duplicated)"
"While processing '{}'", table_expressions[i]->formatForErrorMessage()); "While processing '{}'", table_expressions[i]->formatForErrorMessage());
} }