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

Method initBlockOutputStream

programs/client/Client.cpp:2280–2358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2278 }
2279
2280 void initBlockOutputStream(const Block & block)
2281 {
2282 if (!output_format)
2283 {
2284 /// Ignore all results when fuzzing as they can be huge.
2285 if (query_fuzzer_runs)
2286 {
2287 output_format = std::make_shared<NullOutputFormat>(block);
2288 return;
2289 }
2290
2291 WriteBuffer * out_buf = nullptr;
2292 String pager = config().getString("pager", "");
2293 if (!pager.empty())
2294 {
2295 signal(SIGPIPE, SIG_IGN);
2296 pager_cmd = ShellCommand::execute(pager, true);
2297 out_buf = &pager_cmd->in;
2298 }
2299 else
2300 {
2301 out_buf = &std_out;
2302 }
2303
2304 String current_format = format;
2305
2306 /// The query can specify output format or output file.
2307 /// FIXME: try to prettify this cast using `as<>()`
2308 if (const auto * query_with_output = dynamic_cast<const ASTQueryWithOutput *>(parsed_query.get());
2309 query_with_output && !isOutfileInOtherPlace(context->getSettingsRef()))
2310 {
2311 if (query_with_output->format != nullptr)
2312 {
2313 if (has_vertical_output_suffix)
2314 throw Exception("Output format already specified", ErrorCodes::CLIENT_OUTPUT_FORMAT_SPECIFIED);
2315 current_format = query_with_output->format->as<ASTIdentifier &>().name();
2316 }
2317
2318 if (query_with_output->out_file)
2319 {
2320 // const auto & out_file_node = query_with_output->out_file->as<ASTLiteral &>();
2321 // const auto & out_file = out_file_node.value.safeGet<std::string>();
2322 if (context->getSettingsRef().enable_async_execution)
2323 {
2324 throw Exception(
2325 "If you enable async execution on select query, please set outfile_in_server_with_tcp to 1 and make sure the "
2326 "outfile path is not local",
2327 ErrorCodes::BAD_ARGUMENTS);
2328 }
2329 out_path.emplace(typeid_cast<const ASTLiteral &>(*query_with_output->out_file).value.safeGet<std::string>());
2330 // We are writing to file, so default format is the same as in non-interactive mode.
2331 if (is_interactive && query_with_output->format == nullptr && is_default_format)
2332 current_format = "TabSeparated";
2333
2334 String compression_method_str;
2335 UInt64 compression_level = 1;
2336 OutfileTarget::setOutfileCompression(query_with_output, compression_method_str, compression_level);
2337

Callers

nothing calls this directly

Calls 14

getOutfileBufferMethod · 0.80
outToMultiFileMethod · 0.80
setOutFileTargetMethod · 0.80
configFunction · 0.50
executeFunction · 0.50
ExceptionClass · 0.50
getStringMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45
nameMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected