INTO OUTFILE / FROM INFILE: autodetect FORMAT by file extension

This commit is contained in:
zhongyuankai 2022-01-11 21:26:14 +08:00
parent 878e44eb97
commit 99279c1443
2 changed files with 7 additions and 7 deletions

View File

@ -495,14 +495,11 @@ void ClientBase::initBlockOutputStream(const Block & block, ASTPtr parsed_query)
const auto & id = query_with_output->format->as<ASTIdentifier &>();
current_format = id.name();
}
else
else if (query_with_output->out_file)
{
if (query_with_output->out_file)
{
const auto & format_name = FormatFactory::instance().getFormatFromFileName(out_file);
if (!format_name.empty())
current_format = format_name;
}
const auto & format_name = FormatFactory::instance().getFormatFromFileName(out_file);
if (!format_name.empty())
current_format = format_name;
}
}

View File

@ -14,6 +14,8 @@
#include <Poco/URI.h>
#include <Common/Exception.h>
#include <boost/algorithm/string/case_conv.hpp>
namespace DB
{
@ -411,6 +413,7 @@ String FormatFactory::getFormatFromFileName(String file_name)
return "";
String file_extension = file_name.substr(pos + 1, String::npos);
boost::algorithm::to_lower(file_extension);
return file_extension_formats[file_extension];
}