diff --git a/src/Interpreters/AsynchronousInsertQueue.cpp b/src/Interpreters/AsynchronousInsertQueue.cpp index 461700dcb75..25cd1d0bfa2 100644 --- a/src/Interpreters/AsynchronousInsertQueue.cpp +++ b/src/Interpreters/AsynchronousInsertQueue.cpp @@ -315,7 +315,18 @@ void AsynchronousInsertQueue::preprocessInsertQuery(const ASTPtr & query, const auto sample_block = InterpreterInsertQuery::getSampleBlock(insert_query, table, table->getInMemoryMetadataPtr(), query_context); if (!FormatFactory::instance().isInputFormat(insert_query.format)) - throw Exception(ErrorCodes::UNKNOWN_FORMAT, "Unknown input format {}", insert_query.format); + { + if (insert_query.format.empty() && insert_query.infile) + { + const auto & in_file_node = insert_query.infile->as(); + const auto in_file = in_file_node.value.safeGet(); + const auto in_file_format = FormatFactory::instance().getFormatFromFileName(in_file); + if (!FormatFactory::instance().isInputFormat(in_file_format)) + throw Exception(ErrorCodes::UNKNOWN_FORMAT, "Unknown input INFILE format {}", in_file_format); + } + else + throw Exception(ErrorCodes::UNKNOWN_FORMAT, "Unknown input format {}", insert_query.format); + } /// For table functions we check access while executing /// InterpreterInsertQuery::getTable() -> ITableFunction::execute(). diff --git a/tests/queries/0_stateless/03233_async_insert_infile_format.reference b/tests/queries/0_stateless/03233_async_insert_infile_format.reference new file mode 100644 index 00000000000..ae99738bcc5 --- /dev/null +++ b/tests/queries/0_stateless/03233_async_insert_infile_format.reference @@ -0,0 +1,3 @@ +1 ClickHouse +2 HelloWorld +OK diff --git a/tests/queries/0_stateless/03233_async_insert_infile_format.sh b/tests/queries/0_stateless/03233_async_insert_infile_format.sh new file mode 100755 index 00000000000..2c167b42d51 --- /dev/null +++ b/tests/queries/0_stateless/03233_async_insert_infile_format.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +function cleanup() +{ + [ -e "${CLICKHOUSE_TMP}"/test_infile.csv ] && rm "${CLICKHOUSE_TMP}"/test_infile.csv +} + +trap cleanup EXIT + +cleanup + +echo -e "id,\"word\"\n1,\"ClickHouse\"\n2,\"HelloWorld\"" > "${CLICKHOUSE_TMP}"/test_infile.csv + +${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS async_insert_infile_data;" +${CLICKHOUSE_CLIENT} --query "CREATE TABLE async_insert_infile_data (id UInt32, word String) ENGINE=Memory();" +${CLICKHOUSE_CLIENT} --query "INSERT INTO async_insert_infile_data FROM INFILE '${CLICKHOUSE_TMP}/test_infile.csv' SETTINGS async_insert=1;" +${CLICKHOUSE_CLIENT} --query "SELECT * FROM async_insert_infile_data ORDER BY id;" + +${CLICKHOUSE_CLIENT} --query "INSERT INTO async_insert_infile_data FROM INFILE '${CLICKHOUSE_TMP}/test_infile.csv' SETTINGS async_insert=1 FORMAT NotExists;" 2>&1 | grep -q "UNKNOWN_FORMAT" && echo OK || echo FAIL + +${CLICKHOUSE_CLIENT} --query "DROP TABLE async_insert_infile_data SYNC;"