mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
Merge pull request #32534 from azat/local-file-table-fix
Fix processing initial table (--table/stdin) in clickhouse-local
This commit is contained in:
commit
9ede6beca7
@ -388,12 +388,6 @@ void LocalServer::setupUsers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String LocalServer::getQueryTextPrefix()
|
|
||||||
{
|
|
||||||
return getInitialCreateTableQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LocalServer::connect()
|
void LocalServer::connect()
|
||||||
{
|
{
|
||||||
connection_parameters = ConnectionParameters(config());
|
connection_parameters = ConnectionParameters(config());
|
||||||
@ -463,6 +457,10 @@ try
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
String initial_query = getInitialCreateTableQuery();
|
||||||
|
if (!initial_query.empty())
|
||||||
|
processQueryText(initial_query);
|
||||||
|
|
||||||
if (is_interactive && !delayed_interactive)
|
if (is_interactive && !delayed_interactive)
|
||||||
{
|
{
|
||||||
runInteractive();
|
runInteractive();
|
||||||
|
@ -37,7 +37,6 @@ protected:
|
|||||||
void processError(const String & query) const override;
|
void processError(const String & query) const override;
|
||||||
String getName() const override { return "local"; }
|
String getName() const override { return "local"; }
|
||||||
|
|
||||||
String getQueryTextPrefix() override;
|
|
||||||
void printHelpMessage(const OptionsDescription & options_description) override;
|
void printHelpMessage(const OptionsDescription & options_description) override;
|
||||||
|
|
||||||
void addOptions(OptionsDescription & options_description) override;
|
void addOptions(OptionsDescription & options_description) override;
|
||||||
|
@ -1494,17 +1494,14 @@ void ClientBase::runNonInteractive()
|
|||||||
{
|
{
|
||||||
auto process_multi_query_from_file = [&](const String & file)
|
auto process_multi_query_from_file = [&](const String & file)
|
||||||
{
|
{
|
||||||
auto text = getQueryTextPrefix();
|
|
||||||
String queries_from_file;
|
String queries_from_file;
|
||||||
|
|
||||||
ReadBufferFromFile in(file);
|
ReadBufferFromFile in(file);
|
||||||
readStringUntilEOF(queries_from_file, in);
|
readStringUntilEOF(queries_from_file, in);
|
||||||
|
|
||||||
text += queries_from_file;
|
return executeMultiQuery(queries_from_file);
|
||||||
return executeMultiQuery(text);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Read all queries into `text`.
|
|
||||||
for (const auto & queries_file : queries_files)
|
for (const auto & queries_file : queries_files)
|
||||||
{
|
{
|
||||||
for (const auto & interleave_file : interleave_queries_files)
|
for (const auto & interleave_file : interleave_queries_files)
|
||||||
@ -1519,9 +1516,6 @@ void ClientBase::runNonInteractive()
|
|||||||
}
|
}
|
||||||
|
|
||||||
String text;
|
String text;
|
||||||
if (is_multiquery)
|
|
||||||
text = getQueryTextPrefix();
|
|
||||||
|
|
||||||
if (config().has("query"))
|
if (config().has("query"))
|
||||||
{
|
{
|
||||||
text += config().getRawString("query"); /// Poco configuration should not process substitutions in form of ${...} inside query.
|
text += config().getRawString("query"); /// Poco configuration should not process substitutions in form of ${...} inside query.
|
||||||
|
@ -78,9 +78,6 @@ protected:
|
|||||||
String & query_to_execute, ASTPtr & parsed_query, const String & all_queries_text,
|
String & query_to_execute, ASTPtr & parsed_query, const String & all_queries_text,
|
||||||
std::optional<Exception> & current_exception);
|
std::optional<Exception> & current_exception);
|
||||||
|
|
||||||
/// For non-interactive multi-query mode get queries text prefix.
|
|
||||||
virtual String getQueryTextPrefix() { return ""; }
|
|
||||||
|
|
||||||
static void clearTerminal();
|
static void clearTerminal();
|
||||||
void showClientVersion();
|
void showClientVersion();
|
||||||
|
|
||||||
@ -100,9 +97,10 @@ protected:
|
|||||||
const std::vector<Arguments> & external_tables_arguments) = 0;
|
const std::vector<Arguments> & external_tables_arguments) = 0;
|
||||||
virtual void processConfig() = 0;
|
virtual void processConfig() = 0;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool processQueryText(const String & text);
|
bool processQueryText(const String & text);
|
||||||
|
|
||||||
|
private:
|
||||||
void receiveResult(ASTPtr parsed_query);
|
void receiveResult(ASTPtr parsed_query);
|
||||||
bool receiveAndProcessPacket(ASTPtr parsed_query, bool cancelled);
|
bool receiveAndProcessPacket(ASTPtr parsed_query, bool cancelled);
|
||||||
void receiveLogs(ASTPtr parsed_query);
|
void receiveLogs(ASTPtr parsed_query);
|
||||||
|
7
tests/queries/0_stateless/02140_clickhouse_local_queries_file_table.sh
Executable file
7
tests/queries/0_stateless/02140_clickhouse_local_queries_file_table.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
# shellcheck source=../shell_config.sh
|
||||||
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
|
$CLICKHOUSE_LOCAL --file /dev/null --structure "key String" --input-format TSVWithNamesAndTypes --queries-file <(echo 'select 1') --queries-file <(echo 'select 2') --format Null
|
@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE _local.table\n(\n `key` String\n)\nENGINE = File(\'TSVWithNamesAndTypes\', \'/dev/null\')
|
7
tests/queries/0_stateless/02141_clickhouse_local_interactive_table.sh
Executable file
7
tests/queries/0_stateless/02141_clickhouse_local_interactive_table.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
# shellcheck source=../shell_config.sh
|
||||||
|
. "$CURDIR"/../shell_config.sh
|
||||||
|
|
||||||
|
$CLICKHOUSE_LOCAL --file /dev/null --structure "key String" --input-format TSVWithNamesAndTypes --interactive --send_logs_level=trace <<<'show create table table'
|
Loading…
Reference in New Issue
Block a user