| 1251 | } |
| 1252 | |
| 1253 | JoinPtr SelectQueryExpressionAnalyzer::makeJoin( |
| 1254 | const ASTTablesInSelectQueryElement & join_element, |
| 1255 | const ColumnsWithTypeAndName & left_columns, |
| 1256 | std::optional<ActionsDAG> & left_convert_actions) |
| 1257 | { |
| 1258 | /// Two JOINs are not supported with the same subquery, but different USINGs. |
| 1259 | |
| 1260 | if (joined_plan) |
| 1261 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Table join was already created for query"); |
| 1262 | |
| 1263 | std::optional<ActionsDAG> right_convert_actions; |
| 1264 | |
| 1265 | const auto & analyzed_join = syntax->analyzed_join; |
| 1266 | |
| 1267 | if (auto storage = analyzed_join->getStorageJoin()) |
| 1268 | { |
| 1269 | auto joined_block_actions = analyzed_join->createJoinedBlockActions(getContext(), getPreparedSets()); |
| 1270 | NamesWithAliases required_columns_with_aliases = analyzed_join->getRequiredColumns( |
| 1271 | Block(joined_block_actions.getResultColumns()), joined_block_actions.getRequiredColumns().getNames()); |
| 1272 | |
| 1273 | Names original_right_column_names; |
| 1274 | for (auto & pr : required_columns_with_aliases) |
| 1275 | original_right_column_names.push_back(pr.first); |
| 1276 | |
| 1277 | auto right_columns = storage->getRightSampleBlock().getColumnsWithTypeAndName(); |
| 1278 | std::tie(left_convert_actions, right_convert_actions) = analyzed_join->createConvertingActions(left_columns, right_columns, getContext()); |
| 1279 | return storage->getJoinLocked(analyzed_join, getContext(), original_right_column_names); |
| 1280 | } |
| 1281 | |
| 1282 | joined_plan = buildJoinedPlan(getContext(), getPreparedSets(), join_element, *analyzed_join, query_options); |
| 1283 | |
| 1284 | const ColumnsWithTypeAndName & right_columns = joined_plan->getCurrentHeader()->getColumnsWithTypeAndName(); |
| 1285 | std::tie(left_convert_actions, right_convert_actions) = analyzed_join->createConvertingActions(left_columns, right_columns, getContext()); |
| 1286 | if (right_convert_actions) |
| 1287 | { |
| 1288 | auto converting_step = std::make_unique<ExpressionStep>(joined_plan->getCurrentHeader(), std::move(*right_convert_actions)); |
| 1289 | converting_step->setStepDescription("Convert joined columns"); |
| 1290 | joined_plan->addStep(std::move(converting_step)); |
| 1291 | } |
| 1292 | |
| 1293 | JoinPtr join = chooseJoinAlgorithm(analyzed_join, left_columns, joined_plan, getContext()); |
| 1294 | return join; |
| 1295 | } |
| 1296 | |
| 1297 | ActionsAndProjectInputsFlagPtr SelectQueryExpressionAnalyzer::appendPrewhere( |
| 1298 | ExpressionActionsChain & chain, bool only_types) |
nothing calls this directly
no test coverage detected