Forbid use_structure_from_insertion_table_in_table_functions when execute scalar

This commit is contained in:
flynn 2023-08-12 08:16:44 +00:00
parent 9e7e581813
commit a900d08a5f
4 changed files with 28 additions and 0 deletions

View File

@ -77,6 +77,10 @@ static auto getQueryInterpreter(const ASTSubquery & subquery, ExecuteScalarSubqu
subquery_settings.max_result_rows = 1;
subquery_settings.extremes = false;
subquery_context->setSettings(subquery_settings);
/// When execute `INSERT INTO t WITH ... SELECT ...`, it may lead to `Unknown columns`
/// exception with this settings enabled(https://github.com/ClickHouse/ClickHouse/issues/52494).
subquery_context->getQueryContext()->setSetting("use_structure_from_insertion_table_in_table_functions", false);
if (!data.only_analyze && subquery_context->hasQueryContext())
{
/// Save current cached scalars in the context before analyzing the query

View File

@ -0,0 +1,3 @@
user127 1
user405 1
user902 1

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Tags: no-parallel, no-fasttest
set -e
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
DATA_DIR=$CUR_DIR/data_tsv
$CLICKHOUSE_LOCAL --multiquery \
"CREATE VIEW users AS SELECT * FROM file('$DATA_DIR/mock_data.tsv', TSVWithNamesAndTypes);
CREATE TABLE users_output (name String, tag UInt64)ENGINE = Memory;
INSERT INTO users_output WITH (SELECT groupUniqArrayArray(mapKeys(Tags)) FROM users) AS unique_tags SELECT UserName AS name, length(unique_tags) AS tag FROM users;
SELECT * FROM users_output;"

View File

@ -0,0 +1,5 @@
UserName Age Tags
String Int8 Map(String, UInt64)
user127 20 {'test': 123}
user405 43 {'test': 123}
user902 43 {'test': 123}
1 UserName Age Tags
2 String Int8 Map(String, UInt64)
3 user127 20 {'test': 123}
4 user405 43 {'test': 123}
5 user902 43 {'test': 123}