Better fix

This commit is contained in:
Michael Kolupaev 2024-10-25 09:12:52 +00:00
parent 9cf7247bcc
commit 3da0b2573a
9 changed files with 30 additions and 10 deletions

View File

@ -130,11 +130,6 @@ void applySettingsOverridesForLocal(ContextMutablePtr context)
context->setSettings(settings);
}
LocalServer::LocalServer()
{
is_local = true;
}
Poco::Util::LayeredConfiguration & LocalServer::getClientConfiguration()
{
return config();

View File

@ -23,7 +23,7 @@ namespace DB
class LocalServer : public ClientApplicationBase, public Loggers
{
public:
LocalServer();
LocalServer() = default;
void initialize(Poco::Util::Application & self) override;

View File

@ -1630,6 +1630,11 @@ void ClientBase::sendData(Block & sample, const ColumnsDescription & columns_des
if (!parsed_insert_query)
return;
/// If it's clickhouse-local, and the input data reading is already baked into the query pipeline,
/// don't read the data again here.
if (!connection->isSendDataNeeded())
return;
bool have_data_in_stdin = !is_interactive && !stdin_is_a_tty && isStdinNotEmptyAndValid(std_in);
if (need_render_progress)
@ -1748,8 +1753,7 @@ void ClientBase::sendData(Block & sample, const ColumnsDescription & columns_des
}
else if (!is_interactive)
{
if (!is_local)
sendDataFromStdin(sample, columns_description_for_query, parsed_query);
sendDataFromStdin(sample, columns_description_for_query, parsed_query);
}
else
throw Exception(ErrorCodes::NO_DATA_TO_INSERT, "No data to insert");

View File

@ -263,8 +263,6 @@ protected:
bool is_interactive = false; /// Use either interactive line editing interface or batch mode.
bool delayed_interactive = false;
bool is_local = false; /// clickhouse-local, otherwise clickhouse-client
bool echo_queries = false; /// Print queries before execution in batch mode.
bool ignore_error = false; /// In case of errors, don't print error message, continue to next query. Only applicable for non-interactive mode.

View File

@ -109,6 +109,10 @@ public:
/// Send block of data; if name is specified, server will write it to external (temporary) table of that name.
virtual void sendData(const Block & block, const String & name, bool scalar) = 0;
/// Whether the client needs to read and send the data for the INSERT.
/// False if the server will read the data through other means (in particular if clickhouse-local added input reading step directly into the query pipeline).
virtual bool isSendDataNeeded() const { return true; }
/// Send all contents of external (temporary) tables.
virtual void sendExternalTablesData(ExternalTablesData & data) = 0;

View File

@ -328,6 +328,11 @@ void LocalConnection::sendData(const Block & block, const String &, bool)
sendProfileEvents();
}
bool LocalConnection::isSendDataNeeded() const
{
return !state || state->input_pipeline == nullptr;
}
void LocalConnection::sendCancel()
{
state->is_cancelled = true;

View File

@ -120,6 +120,8 @@ public:
void sendData(const Block & block, const String & name/* = "" */, bool scalar/* = false */) override;
bool isSendDataNeeded() const override;
void sendExternalTablesData(ExternalTablesData &) override;
void sendMergeTreeReadTaskResponse(const ParallelReadResponse & response) override;

View File

@ -9,3 +9,7 @@ bar
bam
# inferred destination table structure
foo
# direct
foo
# infile
foo

View File

@ -32,4 +32,12 @@ echo '# inferred destination table structure'
$CLICKHOUSE_LOCAL --engine_file_truncate_on_insert=1 -q "insert into function file('$tmp_file', 'TSV') select * from input('x String') format LineAsString" <"$tmp_input"
cat "$tmp_file"
echo '# direct'
$CLICKHOUSE_LOCAL --engine_file_truncate_on_insert=1 -q "insert into function file('$tmp_file', 'LineAsString', 'x String') format LineAsString" <"$tmp_input"
cat "$tmp_file"
echo '# infile'
$CLICKHOUSE_LOCAL --engine_file_truncate_on_insert=1 -q "insert into function file('$tmp_file', 'LineAsString', 'x String') from infile '$tmp_input' format LineAsString"
cat "$tmp_file"
rm -f "${tmp_file:?}" "${tmp_input:?}"