MCPcopy Create free account
hub / github.com/ByConity/ByConity / processParsedSingleQuery

Method processParsedSingleQuery

programs/client/Client.cpp:1653–1780  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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>();

Callers

nothing calls this directly

Calls 15

writeStringFunction · 0.85
writeCharFunction · 0.85
connectFunction · 0.85
value_orMethod · 0.80
setCurrentQueryIdMethod · 0.80
getCurrentQueryIdMethod · 0.80
resetProgressMethod · 0.80
checkConnectedMethod · 0.80
tryFindInputFunctionMethod · 0.80
setStringMethod · 0.80
setDefaultDatabaseMethod · 0.80
serializeASTFunction · 0.50

Tested by

no test coverage detected