Skip to content

Commit 2a5d0b0

Browse files
Merge pull request ClickHouse#79046 from ClickHouse/insertion-table
Fix storage of insertion table in client context
2 parents b735fd3 + 87790b7 commit 2a5d0b0

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/Client/ClientBase.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
#include <Access/AccessControl.h>
7373
#include <Storages/ColumnsDescription.h>
74+
#include <TableFunctions/ITableFunction.h>
7475

7576
#include <filesystem>
7677
#include <iostream>
@@ -1706,13 +1707,21 @@ bool ClientBase::receiveSampleBlock(Block & out, ColumnsDescription & columns_de
17061707

17071708
void ClientBase::setInsertionTable(const ASTInsertQuery & insert_query)
17081709
{
1709-
if (!client_context->hasInsertionTable() && insert_query.table)
1710+
if (!client_context->hasInsertionTable())
17101711
{
1711-
String table = insert_query.table->as<ASTIdentifier &>().shortName();
1712-
if (!table.empty())
1712+
if (insert_query.table)
17131713
{
1714-
String database = insert_query.database ? insert_query.database->as<ASTIdentifier &>().shortName() : "";
1715-
client_context->setInsertionTable(StorageID(database, table));
1714+
String table = insert_query.table->as<ASTIdentifier &>().shortName();
1715+
if (!table.empty())
1716+
{
1717+
String database = insert_query.database ? insert_query.database->as<ASTIdentifier &>().shortName() : "";
1718+
client_context->setInsertionTable(StorageID(database, table));
1719+
}
1720+
}
1721+
else if (insert_query.table_function)
1722+
{
1723+
String table_function = insert_query.table_function->as<ASTFunction &>().name;
1724+
client_context->setInsertionTable(StorageID(ITableFunction::getDatabaseName(), table_function));
17161725
}
17171726
}
17181727
}
@@ -2160,6 +2169,7 @@ void ClientBase::processParsedSingleQuery(
21602169
cancelled_printed = false;
21612170
client_exception.reset();
21622171
server_exception.reset();
2172+
client_context->setInsertionTable(StorageID::createEmpty());
21632173

21642174
if (is_interactive)
21652175
{

src/Interpreters/processColumnTransformers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ ASTPtr processColumnTransformers(
6464
const ColumnsDescription & columns,
6565
ASTPtr query_columns)
6666
{
67+
if (table_id.empty())
68+
return processColumnTransformersImpl(columns, {}, query_columns, current_database, StorageID("", "dummy"));
69+
6770
return processColumnTransformersImpl(columns, {}, query_columns, current_database, table_id);
6871
}
6972

tests/queries/0_stateless/02878_use_structure_from_insertion_table_with_explicit_insert_columns.reference

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
42 world
66
42 world
77
42 world
8+
42 world

tests/queries/0_stateless/02878_use_structure_from_insertion_table_with_explicit_insert_columns.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ select * from test order by x;
1717
rm $CLICKHOUSE_TEST_UNIQUE_NAME.native
1818

1919
$CLICKHOUSE_LOCAL -q "select 'world' as y, 42 as x format Values" > $CLICKHOUSE_TEST_UNIQUE_NAME.values
20-
$CLICKHOUSE_LOCAL -q "
20+
$CLICKHOUSE_CLIENT -q "
21+
drop table if exists test_infile;
2122
create table test_infile (val UInt64, key String) engine=Memory;
22-
insert into test_infile select * from file('$CLICKHOUSE_TEST_UNIQUE_NAME.values'); -- { serverError CANNOT_PARSE_TEXT }
2323
insert into test_infile from infile '$CLICKHOUSE_TEST_UNIQUE_NAME.values' FORMAT Values; -- { clientError CANNOT_PARSE_TEXT }
2424
insert into test_infile (key, val) from infile '$CLICKHOUSE_TEST_UNIQUE_NAME.values' FORMAT Values;
2525
insert into test_infile (* EXCEPT 'val', * EXCEPT 'key') from infile '$CLICKHOUSE_TEST_UNIQUE_NAME.values' FORMAT Values;
2626
insert into test_infile (* EXCEPT 'val', test_infile.val) from infile '$CLICKHOUSE_TEST_UNIQUE_NAME.values' FORMAT Values;
27+
insert into table function remote('localhost:9000', $CLICKHOUSE_DATABASE.test_infile) (remote.key, _table_function.remote.val) from infile '$CLICKHOUSE_TEST_UNIQUE_NAME.values' FORMAT Values;
2728
select * from test_infile order by key, val;
2829
"
2930

0 commit comments

Comments
 (0)