mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 13:02:00 +00:00
Merge pull request #56944 from amosbird/fix-56666
Fix a bug with projections and the aggregate_functions_null_for_empty setting during insertion.
This commit is contained in:
commit
119b5ccf76
@ -143,10 +143,19 @@ ASTPtr ASTProjectionSelectQuery::cloneToASTSelect() const
|
||||
if (groupBy())
|
||||
select_query->setExpression(ASTSelectQuery::Expression::GROUP_BY, groupBy()->clone());
|
||||
|
||||
/// Attach settings to prevent AST transformations. We already have ignored AST optimizations
|
||||
/// for projection queries. Only remaining settings need to be added here.
|
||||
///
|
||||
/// NOTE: `count_distinct_implementation` has already been selected during the creation of the
|
||||
/// projection, so there will be no countDistinct(...) to rewrite in projection queries.
|
||||
/// Ideally, we should aim for a unique and normalized query representation that remains
|
||||
/// unchanged after the AST rewrite. For instance, we can add -OrEmpty, realIn as the default
|
||||
/// behavior w.r.t -OrNull, nullIn.
|
||||
auto settings_query = std::make_shared<ASTSetQuery>();
|
||||
SettingsChanges settings_changes;
|
||||
settings_changes.insertSetting("optimize_aggregators_of_group_by_keys", false);
|
||||
settings_changes.insertSetting("optimize_group_by_function_keys", false);
|
||||
settings_changes.insertSetting("aggregate_functions_null_for_empty", false);
|
||||
settings_changes.insertSetting("transform_null_in", false);
|
||||
settings_changes.insertSetting("legacy_column_name_of_tuple_literal", false);
|
||||
settings_query->changes = std::move(settings_changes);
|
||||
settings_query->is_standalone = false;
|
||||
select_query->setExpression(ASTSelectQuery::Expression::SETTINGS, std::move(settings_query));
|
||||
|
@ -0,0 +1,3 @@
|
||||
81920
|
||||
81920
|
||||
81920
|
@ -0,0 +1,29 @@
|
||||
DROP TABLE IF EXISTS aggregate_functions_null_for_empty;
|
||||
|
||||
CREATE TABLE aggregate_functions_null_for_empty (`x` UInt32, `y` UInt64, PROJECTION p (SELECT sum(y))) ENGINE = MergeTree ORDER BY tuple();
|
||||
|
||||
INSERT INTO aggregate_functions_null_for_empty SELECT number, number * 2 FROM numbers(8192 * 10) SETTINGS aggregate_functions_null_for_empty = true;
|
||||
|
||||
SELECT count() FROM aggregate_functions_null_for_empty;
|
||||
|
||||
DROP TABLE aggregate_functions_null_for_empty;
|
||||
|
||||
DROP TABLE IF EXISTS transform_null_in;
|
||||
|
||||
CREATE TABLE transform_null_in (`x` UInt32, `y` UInt64, PROJECTION p (SELECT sum(y in (1,2,3)))) ENGINE = MergeTree ORDER BY tuple();
|
||||
|
||||
INSERT INTO transform_null_in SELECT number, number * 2 FROM numbers(8192 * 10) SETTINGS transform_null_in = true;
|
||||
|
||||
SELECT count() FROM transform_null_in;
|
||||
|
||||
DROP TABLE transform_null_in;
|
||||
|
||||
DROP TABLE IF EXISTS legacy_column_name_of_tuple_literal;
|
||||
|
||||
CREATE TABLE legacy_column_name_of_tuple_literal (`x` UInt32, `y` UInt64, PROJECTION p (SELECT sum(y in (1,2,3)))) ENGINE = MergeTree ORDER BY tuple();
|
||||
|
||||
INSERT INTO legacy_column_name_of_tuple_literal SELECT number, number * 2 FROM numbers(8192 * 10) SETTINGS legacy_column_name_of_tuple_literal = true;
|
||||
|
||||
SELECT count() FROM legacy_column_name_of_tuple_literal;
|
||||
|
||||
DROP TABLE legacy_column_name_of_tuple_literal;
|
Loading…
Reference in New Issue
Block a user