From 9b7cd64093a79ff51b28a912501ce028618f88a5 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Sun, 5 Feb 2023 14:30:04 +0100 Subject: [PATCH] Analyzer join_use_nulls fix --- src/Analyzer/Passes/QueryAnalysisPass.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Analyzer/Passes/QueryAnalysisPass.cpp b/src/Analyzer/Passes/QueryAnalysisPass.cpp index c6b83ac3e14..18da324fea9 100644 --- a/src/Analyzer/Passes/QueryAnalysisPass.cpp +++ b/src/Analyzer/Passes/QueryAnalysisPass.cpp @@ -2960,14 +2960,21 @@ QueryTreeNodePtr QueryAnalyzer::tryResolveIdentifierFromJoin(const IdentifierLoo bool join_use_nulls = scope.context->getSettingsRef().join_use_nulls; - if (join_use_nulls - && (isFull(join_kind) || - (isLeft(join_kind) && resolved_side && *resolved_side == JoinTableSide::Right) || - (isRight(join_kind) && resolved_side && *resolved_side == JoinTableSide::Left))) + if (join_use_nulls && + resolved_identifier->getNodeType() == QueryTreeNodeType::COLUMN && + (isFull(join_kind) || + (isLeft(join_kind) && resolved_side && *resolved_side == JoinTableSide::Right) || + (isRight(join_kind) && resolved_side && *resolved_side == JoinTableSide::Left))) { resolved_identifier = resolved_identifier->clone(); auto & resolved_column = resolved_identifier->as(); - resolved_column.setColumnType(makeNullable(resolved_column.getColumnType())); + const auto & resolved_column_type = resolved_column.getColumnType(); + const auto & resolved_column_name = resolved_column.getColumnName(); + + auto to_nullable_function_resolver = FunctionFactory::instance().get("toNullable", scope.context); + auto to_nullable_function_arguments = {ColumnWithTypeAndName(nullptr, resolved_column_type, resolved_column_name)}; + auto to_nullable_function = to_nullable_function_resolver->build(to_nullable_function_arguments); + resolved_column.setColumnType(to_nullable_function->getResultType()); } return resolved_identifier;