Parameters are in global variables: 'parsed_query' -- the query AST, 'query_to_send' -- the query text that is sent to server, 'full_query' -- for INSERT queries, contains the query and the data that follow it. Its memory is referenced by ASTInsertQuery::begin, end.
| 1651 | // 'full_query' -- for INSERT queries, contains the query and the data that |
| 1652 | // follow it. Its memory is referenced by ASTInsertQuery::begin, end. |
| 1653 | void processParsedSingleQuery(std::optional<bool> echo_query = {}) |
| 1654 | { |
| 1655 | resetOutput(); |
| 1656 | client_exception.reset(); |
| 1657 | server_exception.reset(); |
| 1658 | have_error = false; |
| 1659 | |
| 1660 | if (echo_query.value_or(echo_queries)) |
| 1661 | { |
| 1662 | if (echo_pretty) |
| 1663 | writeString(serializeAST(*parsed_query, false), std_out); |
| 1664 | else |
| 1665 | writeString(full_query, std_out); |
| 1666 | writeChar('\n', std_out); |
| 1667 | std_out.next(); |
| 1668 | } |
| 1669 | |
| 1670 | if (is_interactive) |
| 1671 | { |
| 1672 | // Generate a new query_id |
| 1673 | context->setCurrentQueryId(""); |
| 1674 | for (const auto & query_id_format : query_id_formats) |
| 1675 | { |
| 1676 | writeString(query_id_format.first, std_out); |
| 1677 | writeString(fmt::format(query_id_format.second, fmt::arg("query_id", context->getCurrentQueryId())), std_out); |
| 1678 | writeChar('\n', std_out); |
| 1679 | std_out.next(); |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | processed_rows = 0; |
| 1684 | written_first_block = false; |
| 1685 | progress_indication.resetProgress(); |
| 1686 | |
| 1687 | { |
| 1688 | /// Temporarily apply query settings to context. |
| 1689 | std::optional<Settings> old_settings; |
| 1690 | SCOPE_EXIT_SAFE({ |
| 1691 | if (old_settings) |
| 1692 | context->setSettings(*old_settings); |
| 1693 | }); |
| 1694 | auto apply_query_settings = [&](const IAST & settings_ast) { |
| 1695 | if (!old_settings) |
| 1696 | old_settings.emplace(context->getSettingsRef()); |
| 1697 | context->applySettingsChanges(settings_ast.as<ASTSetQuery>()->changes); |
| 1698 | }; |
| 1699 | const auto * insert = parsed_query->as<ASTInsertQuery>(); |
| 1700 | if (const auto * select = parsed_query->as<ASTSelectQuery>(); select && select->settings()) |
| 1701 | apply_query_settings(*select->settings()); |
| 1702 | else if (const auto * select_with_union = parsed_query->as<ASTSelectWithUnionQuery>()) |
| 1703 | { |
| 1704 | const ASTs & children = select_with_union->list_of_selects->children; |
| 1705 | if (!children.empty()) |
| 1706 | { |
| 1707 | // On the client it is enough to apply settings only for the |
| 1708 | // last SELECT, since the only thing that is important to apply |
| 1709 | // on the client is format settings. |
| 1710 | const auto * last_select = children.back()->as<ASTSelectQuery>(); |
nothing calls this directly
no test coverage detected