Fix style error and test cases error

This commit is contained in:
hexiaoting 2021-02-09 18:08:55 +08:00
parent 2c278f1e02
commit 28b981a76b
4 changed files with 14 additions and 2 deletions

View File

@ -80,6 +80,9 @@ void CollectJoinOnKeysMatcher::visit(const ASTFunction & func, const ASTPtr & as
ASTPtr right = func.arguments->children.at(1);
auto table_numbers = getTableNumbers(left, right, data);
if (table_numbers.first != table_numbers.second && table_numbers.first > 0 && table_numbers.second > 0)
data.new_on_expression_valid = true;
/**
* if this is an inner join and the expression related to less than 2 tables, then move it to WHERE
*/
@ -108,6 +111,9 @@ void CollectJoinOnKeysMatcher::visit(const ASTFunction & func, const ASTPtr & as
ASTPtr right = func.arguments->children.at(1);
auto table_numbers = getTableNumbers(left, right, data);
if (table_numbers.first != table_numbers.second && table_numbers.first > 0 && table_numbers.second > 0)
data.new_on_expression_valid = true;
if (data.kind == ASTTableJoin::Kind::Inner
&& (table_numbers.first == table_numbers.second || table_numbers.first == 0 || table_numbers.second == 0))
{

View File

@ -37,6 +37,7 @@ public:
ASTPtr new_on_expression{};
ASTPtr new_where_conditions{};
bool has_some{false};
bool new_on_expression_valid{false};
void addJoinKeys(const ASTPtr & left_ast, const ASTPtr & right_ast, const std::pair<size_t, size_t> & table_no);
void addAsofJoinKeys(const ASTPtr & left_ast, const ASTPtr & right_ast, const std::pair<size_t, size_t> & table_no,

View File

@ -425,6 +425,9 @@ void collectJoinedColumns(TableJoin & analyzed_join, const ASTSelectQuery & sele
ErrorCodes::INVALID_JOIN_ON_EXPRESSION);
if (is_asof)
data.asofToJoinKeys();
else if (!data.new_on_expression_valid)
throw Exception("JOIN expects left and right joined keys from two joined table in ON section. Unexpected '" + queryToString(data.new_on_expression) + "'",
ErrorCodes::INVALID_JOIN_ON_EXPRESSION);
else if (data.new_where_conditions != nullptr)
{
table_join.on_expression = data.new_on_expression;

View File

@ -23,6 +23,7 @@ join_use_nulls = 1
-
\N \N
-
1 1 \N \N
2 2 \N \N
-
1 1 1 1
@ -50,6 +51,7 @@ join_use_nulls = 0
-
-
-
1 1 0 0
2 2 0 0
-
1 1 1 1