mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
Merge pull request #29014 from vdimir/issue-29007-dict-join-strictness
Check left join strictness in tryInitDictJoin
This commit is contained in:
commit
69e59f34da
@ -1095,7 +1095,7 @@ IColumn::Filter dictionaryJoinRightColumns(const TableJoin & table_join, AddedCo
|
|||||||
std::move(key_getter), nullptr, added_columns, null_map, flags);
|
std::move(key_getter), nullptr, added_columns, null_map, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Exception("Logical error: wrong JOIN combination", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong JOIN combination: {} {}", STRICTNESS, KIND);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /// nameless
|
} /// nameless
|
||||||
@ -1414,13 +1414,13 @@ void HashJoin::joinBlock(Block & block, ExtraBlockPtr & not_processed)
|
|||||||
joinBlockImpl<Kind::Left, Strictness::Anti>(block, key_names_left, sample_block_with_columns_to_add, map);
|
joinBlockImpl<Kind::Left, Strictness::Anti>(block, key_names_left, sample_block_with_columns_to_add, map);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw Exception("Logical error: wrong JOIN combination", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong JOIN combination: dictionary + {} {}", strictness, kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (kind == Kind::Inner && strictness == Strictness::All)
|
else if (kind == Kind::Inner && strictness == Strictness::All)
|
||||||
joinBlockImpl<Kind::Left, Strictness::Semi>(block, key_names_left, sample_block_with_columns_to_add, map);
|
joinBlockImpl<Kind::Left, Strictness::Semi>(block, key_names_left, sample_block_with_columns_to_add, map);
|
||||||
else
|
else
|
||||||
throw Exception("Logical error: wrong JOIN combination", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong JOIN combination: dictionary + {} {}", strictness, kind);
|
||||||
}
|
}
|
||||||
else if (joinDispatch(kind, strictness, data->maps, [&](auto kind_, auto strictness_, auto & map)
|
else if (joinDispatch(kind, strictness, data->maps, [&](auto kind_, auto strictness_, auto & map)
|
||||||
{
|
{
|
||||||
@ -1432,7 +1432,7 @@ void HashJoin::joinBlock(Block & block, ExtraBlockPtr & not_processed)
|
|||||||
else if (kind == ASTTableJoin::Kind::Cross)
|
else if (kind == ASTTableJoin::Kind::Cross)
|
||||||
joinBlockImplCross(block, not_processed);
|
joinBlockImplCross(block, not_processed);
|
||||||
else
|
else
|
||||||
throw Exception("Logical error: unknown combination of JOIN", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong JOIN combination: {} {}", strictness, kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Mapped>
|
template <typename Mapped>
|
||||||
@ -1494,7 +1494,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!joinDispatch(parent.kind, parent.strictness, parent.data->maps, fill_callback))
|
if (!joinDispatch(parent.kind, parent.strictness, parent.data->maps, fill_callback))
|
||||||
throw Exception("Logical error: unknown JOIN strictness (must be on of: ANY, ALL, ASOF)", ErrorCodes::LOGICAL_ERROR);
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown JOIN strictness '{}' (must be on of: ANY, ALL, ASOF)", parent.strictness);
|
||||||
|
|
||||||
fillNullsFromBlocks(columns_right, rows_added);
|
fillNullsFromBlocks(columns_right, rows_added);
|
||||||
return rows_added;
|
return rows_added;
|
||||||
|
@ -339,8 +339,16 @@ static std::optional<String> getDictKeyName(const String & dict_name , ContextPt
|
|||||||
|
|
||||||
bool TableJoin::tryInitDictJoin(const Block & sample_block, ContextPtr context)
|
bool TableJoin::tryInitDictJoin(const Block & sample_block, ContextPtr context)
|
||||||
{
|
{
|
||||||
|
using Strictness = ASTTableJoin::Strictness;
|
||||||
|
|
||||||
|
bool allowed_inner = isInner(kind()) && strictness() == Strictness::All;
|
||||||
|
bool allowed_left = isLeft(kind()) && (strictness() == Strictness::Any ||
|
||||||
|
strictness() == Strictness::All ||
|
||||||
|
strictness() == Strictness::Semi ||
|
||||||
|
strictness() == Strictness::Anti);
|
||||||
|
|
||||||
/// Support ALL INNER, [ANY | ALL | SEMI | ANTI] LEFT
|
/// Support ALL INNER, [ANY | ALL | SEMI | ANTI] LEFT
|
||||||
if (!isLeft(kind()) && !(isInner(kind()) && strictness() == ASTTableJoin::Strictness::All))
|
if (!allowed_inner && !allowed_left)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Names & right_keys = keyNamesRight();
|
const Names & right_keys = keyNamesRight();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Parsers/IAST.h>
|
#include <Parsers/IAST.h>
|
||||||
|
#include <common/EnumReflection.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
|
@ -16,6 +16,12 @@ flat: any left
|
|||||||
2 2 2 2
|
2 2 2 2
|
||||||
3 3 3 3
|
3 3 3 3
|
||||||
4 0 0
|
4 0 0
|
||||||
|
flat: any left + any_join_distinct_right_table_keys
|
||||||
|
0 0 0 0
|
||||||
|
1 1 1 1
|
||||||
|
2 2 2 2
|
||||||
|
3 3 3 3
|
||||||
|
4 0 0
|
||||||
flat: semi left
|
flat: semi left
|
||||||
0 0 0 0
|
0 0 0 0
|
||||||
1 1 1 1
|
1 1 1 1
|
||||||
|
@ -33,6 +33,8 @@ SELECT 'flat: left';
|
|||||||
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d USING(key) ORDER BY key;
|
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 LEFT JOIN dict_flat d USING(key) ORDER BY key;
|
||||||
SELECT 'flat: any left';
|
SELECT 'flat: any left';
|
||||||
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key;
|
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key;
|
||||||
|
SELECT 'flat: any left + any_join_distinct_right_table_keys'; -- falls back to regular join
|
||||||
|
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 ANY LEFT JOIN dict_flat d USING(key) ORDER BY key SETTINGS any_join_distinct_right_table_keys = '1';
|
||||||
SELECT 'flat: semi left';
|
SELECT 'flat: semi left';
|
||||||
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 SEMI JOIN dict_flat d USING(key) ORDER BY key;
|
SELECT * FROM (SELECT number AS key FROM numbers(5)) s1 SEMI JOIN dict_flat d USING(key) ORDER BY key;
|
||||||
SELECT 'flat: anti left';
|
SELECT 'flat: anti left';
|
||||||
|
Loading…
Reference in New Issue
Block a user