Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #46350 to 23.1: Fix LOGICAL_ERROR in async inserts with invalid data in format VALUES #46448

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Processors/Formats/Impl/ValuesBlockInputFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ void ValuesBlockInputFormat::readSuffix()

void ValuesBlockInputFormat::resetParser()
{
if (got_exception)
{
/// In case of exception always reset the templates and parser type,
/// because they may be in the invalid state.
for (size_t i = 0; i < num_columns; ++i)
{
templates[i].reset();
parser_type_for_column[i] = ParserType::Streaming;
}
}

IInputFormat::resetParser();
// I'm not resetting parser modes here.
// There is a good chance that all messages have the same format.
Expand Down
1 change: 1 addition & 0 deletions src/Processors/ISource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void ISource::work()
catch (...)
{
finished = true;
got_exception = true;
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SYNTAX_ERROR
good string
23 changes: 23 additions & 0 deletions tests/queries/0_stateless/02563_async_insert_bad_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh

${CLICKHOUSE_CLIENT} -q "DROP TABLE IF EXISTS t_async_insert_bad_data"
${CLICKHOUSE_CLIENT} -q "CREATE TABLE t_async_insert_bad_data (d Date, s String) ENGINE = Memory"

${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&async_insert=1" -X POST \
--data-binary "INSERT INTO t_async_insert_bad_data VALUES (now(), 'bad'string')" 2>&1 | grep -o SYNTAX_ERROR &

# Sleep to avoid reordering of inserts. It doesn't affect the correctness
# of test, but allows to reproduce a bug more often in old versions.
sleep 0.02

${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}&async_insert=1" -X POST \
--data-binary "INSERT INTO t_async_insert_bad_data VALUES (now(), 'good string')" &

wait

${CLICKHOUSE_CLIENT} -q "SELECT s FROM t_async_insert_bad_data ORDER BY s"
${CLICKHOUSE_CLIENT} -q "DROP TABLE IF EXISTS t_async_insert_bad_data"