1#pragma once
2
3#include <Core/QueryProcessingStage.h>
4#include <DataStreams/BlockIO.h>
5
6#include <Processors/QueryPipeline.h>
7
8namespace DB
9{
10
11class ReadBuffer;
12class WriteBuffer;
13class Context;
14
15
16/// Parse and execute a query.
17void executeQuery(
18 ReadBuffer & istr, /// Where to read query from (and data for INSERT, if present).
19 WriteBuffer & ostr, /// Where to write query output to.
20 bool allow_into_outfile, /// If true and the query contains INTO OUTFILE section, redirect output to that file.
21 Context & context, /// DB, tables, data types, storage engines, functions, aggregate functions...
22 std::function<void(const String &)> set_content_type, /// If non-empty callback is passed, it will be called with the Content-Type of the result.
23 std::function<void(const String &)> set_query_id /// If non-empty callback is passed, it will be called with the query id.
24);
25
26
27/// More low-level function for server-to-server interaction.
28/// Prepares a query for execution but doesn't execute it.
29/// Returns a pair of block streams which, when used, will result in query execution.
30/// This means that the caller can to the extent control the query execution pipeline.
31///
32/// To execute:
33/// * if present, write INSERT data into BlockIO::out
34/// * then read the results from BlockIO::in.
35///
36/// If the query doesn't involve data insertion or returning of results, out and in respectively
37/// will be equal to nullptr.
38///
39/// Correctly formatting the results (according to INTO OUTFILE and FORMAT sections)
40/// must be done separately.
41BlockIO executeQuery(
42 const String & query, /// Query text without INSERT data. The latter must be written to BlockIO::out.
43 Context & context, /// DB, tables, data types, storage engines, functions, aggregate functions...
44 bool internal = false, /// If true, this query is caused by another query and thus needn't be registered in the ProcessList.
45 QueryProcessingStage::Enum stage = QueryProcessingStage::Complete, /// To which stage the query must be executed.
46 bool may_have_embedded_data = false, /// If insert query may have embedded data
47 bool allow_processors = true /// If can use processors pipeline
48);
49
50
51QueryPipeline executeQueryWithProcessors(
52 const String & query, /// Query text without INSERT data. The latter must be written to BlockIO::out.
53 Context & context, /// DB, tables, data types, storage engines, functions, aggregate functions...
54 bool internal = false, /// If true, this query is caused by another query and thus needn't be registered in the ProcessList.
55 QueryProcessingStage::Enum stage = QueryProcessingStage::Complete, /// To which stage the query must be executed.
56 bool may_have_embedded_data = false /// If insert query may have embedded data
57);
58
59}
60