MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / sendData

Method sendData

src/Client/ClientBase.cpp:2051–2210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2049
2050
2051void ClientBase::sendData(Block & sample, const ColumnsDescription & columns_description, ASTPtr parsed_query)
2052{
2053 /// Get columns description from variable or (if it was empty) create it from sample.
2054 auto columns_description_for_query = columns_description.empty() ? ColumnsDescription(sample.getNamesAndTypesList()) : columns_description;
2055 if (columns_description_for_query.empty())
2056 {
2057 throw Exception(ErrorCodes::LOGICAL_ERROR,
2058 "Column description is empty and it can't be built from sample from table. "
2059 "Cannot execute query.");
2060 }
2061
2062 /// If INSERT data must be sent.
2063 auto * parsed_insert_query = parsed_query->as<ASTInsertQuery>();
2064 if (!parsed_insert_query)
2065 return;
2066
2067 /// If it's clickhouse-local, and the input data reading is already baked into the query pipeline,
2068 /// don't read the data again here. This happens in some cases (e.g. input() table function) but not others (e.g. INFILE).
2069 if (!connection->isSendDataNeeded())
2070 return;
2071
2072 bool have_data_in_stdin = !is_interactive && !stdin_is_a_tty && isStdinNotEmptyAndValid(*std_in);
2073
2074 if (need_render_progress)
2075 {
2076 if (auto * std_in_desc = typeid_cast<ReadBufferFromFileDescriptor *>(std_in.get()))
2077 {
2078 /// Set total_bytes_to_read for current fd.
2079 FileProgress file_progress(0, std_in_desc->getFileSize());
2080 progress_indication.updateProgress(Progress(file_progress));
2081
2082 /// Set callback to be called on file progress.
2083 if (tty_buf)
2084 progress_indication.setFileProgressCallback(client_context, *tty_buf, tty_mutex);
2085 }
2086 }
2087
2088 /// If data fetched from file (maybe compressed file)
2089 if (parsed_insert_query->infile)
2090 {
2091 if (isEmbeeddedClient())
2092 throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Reading from INFILE is disabled when you are running client embedded into server.");
2093
2094 /// Get name of this file (path to file)
2095 const auto & in_file_node = parsed_insert_query->infile->as<ASTLiteral &>();
2096 const auto in_file = in_file_node.value.safeGet<std::string>();
2097
2098 std::string compression_method;
2099 /// Compression method can be specified in query
2100 if (parsed_insert_query->compression)
2101 {
2102 const auto & compression_method_node = parsed_insert_query->compression->as<ASTLiteral &>();
2103 compression_method = compression_method_node.value.safeGet<std::string>();
2104 }
2105
2106 String current_format = parsed_insert_query->format;
2107 if (current_format.empty())
2108 current_format = FormatFactory::instance().getFormatFromFileName(in_file);

Callers 1

sendDataFromPipeMethod · 0.45

Calls 15

isStdinNotEmptyAndValidFunction · 0.85
getFormatSettingsFunction · 0.85
getNumberOfCPUCoresToUseFunction · 0.85
getFormatFromFileNameMethod · 0.80
getInsertableMethod · 0.80
getCurrentDatabaseMethod · 0.80
ColumnsDescriptionClass · 0.70
ExceptionClass · 0.70
ProgressClass · 0.50
parseFunction · 0.50

Tested by

no test coverage detected