Fix build after resolving conflicts

This commit is contained in:
vdimir 2022-08-04 15:15:49 +00:00
parent d1aea19987
commit 442ffb0349
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
4 changed files with 27 additions and 95 deletions

View File

@ -69,21 +69,21 @@ DirectKeyValueJoin::DirectKeyValueJoin(std::shared_ptr<TableJoin> table_join_,
, right_sample_block(right_sample_block_)
, log(&Poco::Logger::get("DirectKeyValueJoin"))
{
if (!table_join->oneDisjunct()
|| table_join->getOnlyClause().key_names_left.size() != 1
|| table_join->getOnlyClause().key_names_right.size() != 1)
if (!table_join->oneDisjunct() ||
table_join->getOnlyClause().key_names_left.size() != 1 ||
table_join->getOnlyClause().key_names_right.size() != 1)
{
throw DB::Exception(ErrorCodes::UNSUPPORTED_JOIN_KEYS, "Not supported by direct JOIN");
}
bool allowed_inner = isInner(table_join->kind()) && (table_join->strictness() == ASTTableJoin::Strictness::All ||
table_join->strictness() == ASTTableJoin::Strictness::Any ||
bool allowed_inner = isInner(table_join->kind()) && (table_join->strictness() == JoinStrictness::All ||
table_join->strictness() == JoinStrictness::Any ||
table_join->strictness() != JoinStrictness::RightAny);
bool allowed_left = isLeft(table_join->kind()) && (table_join->strictness() == ASTTableJoin::Strictness::Any ||
table_join->strictness() == ASTTableJoin::Strictness::All ||
table_join->strictness() == ASTTableJoin::Strictness::Semi ||
table_join->strictness() == ASTTableJoin::Strictness::Anti);
bool allowed_left = isLeft(table_join->kind()) && (table_join->strictness() == JoinStrictness::Any ||
table_join->strictness() == JoinStrictness::All ||
table_join->strictness() == JoinStrictness::Semi ||
table_join->strictness() == JoinStrictness::Anti);
if (!allowed_inner && !allowed_left)
{
throw DB::Exception(ErrorCodes::NOT_IMPLEMENTED, "Strictness {} and kind {} is not supported by direct JOIN",
@ -128,8 +128,8 @@ void DirectKeyValueJoin::joinBlock(Block & block, std::shared_ptr<ExtraBlock> &)
block.insert(std::move(col));
}
bool is_semi_join = table_join->strictness() == ASTTableJoin::Strictness::Semi;
bool is_anti_join = table_join->strictness() == ASTTableJoin::Strictness::Anti;
bool is_semi_join = table_join->strictness() == JoinStrictness::Semi;
bool is_anti_join = table_join->strictness() == JoinStrictness::Anti;
if (is_anti_join)
{

View File

@ -113,6 +113,8 @@ bool allowEarlyConstantFolding(const ActionsDAG & actions, const Settings & sett
return true;
}
Poco::Logger * getLogger() { return &Poco::Logger::get("ExpressionAnalyzer"); }
}
bool sanitizeBlock(Block & block, bool throw_if_cannot_create_column)
@ -1006,6 +1008,7 @@ static ActionsDAGPtr createJoinedBlockActions(ContextPtr context, const TableJoi
return ExpressionAnalyzer(expression_list, syntax_result, context).getActionsDAG(true, false);
}
std::shared_ptr<DirectKeyValueJoin> tryDictJoin(std::shared_ptr<TableJoin> analyzed_join, const Block & right_sample_block, ContextPtr context);
std::shared_ptr<DirectKeyValueJoin> tryKeyValueJoin(std::shared_ptr<TableJoin> analyzed_join, const Block & right_sample_block);
static std::shared_ptr<IJoin> chooseJoinAlgorithm(std::shared_ptr<TableJoin> analyzed_join, std::unique_ptr<QueryPlan> & joined_plan, ContextPtr context)
@ -1016,7 +1019,7 @@ static std::shared_ptr<IJoin> chooseJoinAlgorithm(std::shared_ptr<TableJoin> ana
{
JoinPtr direct_join = nullptr;
direct_join = direct_join ? direct_join : tryKeyValueJoin(analyzed_join, right_sample_block);
direct_join = direct_join ? direct_join : tryDictJoin(analyzed_join, right_sample_block, getContext());
direct_join = direct_join ? direct_join : tryDictJoin(analyzed_join, right_sample_block, context);
if (direct_join)
{
@ -1111,23 +1114,21 @@ static std::unique_ptr<QueryPlan> buildJoinedPlan(
std::shared_ptr<DirectKeyValueJoin> tryDictJoin(std::shared_ptr<TableJoin> analyzed_join, const Block & right_sample_block, ContextPtr context)
{
using Strictness = ASTTableJoin::Strictness;
bool allowed_inner = isInner(analyzed_join->kind()) && analyzed_join->strictness() == Strictness::All;
bool allowed_left = isLeft(analyzed_join->kind()) && (analyzed_join->strictness() == Strictness::Any ||
analyzed_join->strictness() == Strictness::All ||
analyzed_join->strictness() == Strictness::Semi ||
analyzed_join->strictness() == Strictness::Anti);
bool allowed_inner = isInner(analyzed_join->kind()) && analyzed_join->strictness() == JoinStrictness::All;
bool allowed_left = isLeft(analyzed_join->kind()) && (analyzed_join->strictness() == JoinStrictness::Any ||
analyzed_join->strictness() == JoinStrictness::All ||
analyzed_join->strictness() == JoinStrictness::Semi ||
analyzed_join->strictness() == JoinStrictness::Anti);
if (!allowed_inner && !allowed_left)
{
LOG_TRACE(&Poco::Logger::get("tryDictJoin"), "Can't use dictionary join: {} {} is not supported",
LOG_TRACE(getLogger(), "Can't use dictionary join: {} {} is not supported",
analyzed_join->kind(), analyzed_join->strictness());
return nullptr;
}
if (analyzed_join->getClauses().size() != 1 || analyzed_join->getClauses()[0].key_names_right.size() != 1)
{
LOG_TRACE(&Poco::Logger::get("tryDictJoin"), "Can't use dictionary join: only one key is supported");
LOG_TRACE(getLogger(), "Can't use dictionary join: only one key is supported");
return nullptr;
}
@ -1136,7 +1137,7 @@ std::shared_ptr<DirectKeyValueJoin> tryDictJoin(std::shared_ptr<TableJoin> analy
const auto & dictionary_name = analyzed_join->getRightStorageName();
if (dictionary_name.empty())
{
LOG_TRACE(&Poco::Logger::get("tryDictJoin"), "Can't use dictionary join: dictionary was not found");
LOG_TRACE(getLogger(), "Can't use dictionary join: dictionary was not found");
return nullptr;
}
@ -1145,14 +1146,14 @@ std::shared_ptr<DirectKeyValueJoin> tryDictJoin(std::shared_ptr<TableJoin> analy
auto dictionary = dictionary_helper.getDictionary(dictionary_name);
if (!dictionary)
{
LOG_TRACE(&Poco::Logger::get("tryDictJoin"), "Can't use dictionary join: dictionary was not found");
LOG_TRACE(getLogger(), "Can't use dictionary join: dictionary was not found");
return nullptr;
}
const auto & dict_keys = dictionary->getStructure().getKeysNames();
if (dict_keys.size() != 1 || dict_keys[0] != analyzed_join->getOriginalName(right_key))
{
LOG_TRACE(&Poco::Logger::get("tryDictJoin"), "Can't use dictionary join: join key '{}' doesn't natch to dictionary key ({})",
LOG_TRACE(getLogger(), "Can't use dictionary join: join key '{}' doesn't natch to dictionary key ({})",
right_key, fmt::join(dict_keys, ", "));
return nullptr;
}

View File

@ -266,7 +266,7 @@ HashJoin::HashJoin(std::shared_ptr<TableJoin> table_join_, const Block & right_s
const auto & key_names_right = clause.key_names_right;
ColumnRawPtrs key_columns = JoinCommon::extractKeysForJoin(right_table_keys, key_names_right);
if (strictness == ASTTableJoin::Strictness::Asof)
if (strictness == JoinStrictness::Asof)
{
assert(disjuncts_num == 1);
@ -459,7 +459,7 @@ struct KeyGetterForType
void HashJoin::dataMapInit(MapsVariant & map)
{
if (kind == ASTTableJoin::Kind::Cross)
if (kind == JoinKind::Cross)
return;
joinDispatchInit(kind, strictness, map);
joinDispatch(kind, strictness, map, [&](auto, auto, auto & map_) { map_.create(data->type); });

View File

@ -416,75 +416,6 @@ bool TableJoin::needStreamWithNonJoinedRows() const
return isRightOrFull(kind());
}
static std::optional<String> getDictKeyName(const String & dict_name , ContextPtr context)
{
auto dictionary = context->getExternalDictionariesLoader().getDictionary(dict_name, context);
if (!dictionary)
return {};
if (const auto & structure = dictionary->getStructure(); structure.id)
return structure.id->name;
return {};
}
bool TableJoin::tryInitDictJoin(const Block & sample_block, ContextPtr context)
{
bool allowed_inner = isInner(kind()) && strictness() == JoinStrictness::All;
bool allowed_left = isLeft(kind()) && (strictness() == JoinStrictness::Any ||
strictness() == JoinStrictness::All ||
strictness() == JoinStrictness::Semi ||
strictness() == JoinStrictness::Anti);
/// Support ALL INNER, [ANY | ALL | SEMI | ANTI] LEFT
if (!allowed_inner && !allowed_left)
return false;
if (clauses.size() != 1 || clauses[0].key_names_right.size() != 1)
return false;
const auto & right_key = getOnlyClause().key_names_right[0];
/// TODO: support 'JOIN ... ON expr(dict_key) = table_key'
auto it_key = original_names.find(right_key);
if (it_key == original_names.end())
return false;
if (!right_storage_dictionary)
return false;
auto dict_name = right_storage_dictionary->getDictionaryName();
auto dict_key = getDictKeyName(dict_name, context);
if (!dict_key.has_value() || *dict_key != it_key->second)
return false; /// JOIN key != Dictionary key
Names src_names;
NamesAndTypesList dst_columns;
for (const auto & col : sample_block)
{
if (col.name == right_key)
continue; /// do not extract key column
auto it = original_names.find(col.name);
if (it != original_names.end())
{
String original = it->second;
src_names.push_back(original);
dst_columns.push_back({col.name, col.type});
}
else
{
/// Can't extract column from dictionary table
/// TODO: Sometimes it should be possible to recunstruct required column,
/// e.g. if it's an expression depending on dictionary attributes
return false;
}
}
dictionary_reader = std::make_shared<DictionaryReader>(dict_name, src_names, dst_columns, context);
return true;
}
static void renameIfNeeded(String & name, const NameToNameMap & renames)
{
if (const auto it = renames.find(name); it != renames.end())