diff --git a/src/Processors/Transforms/buildPushingToViewsChain.cpp b/src/Processors/Transforms/buildPushingToViewsChain.cpp index ea10b025e87..781a162d2bd 100644 --- a/src/Processors/Transforms/buildPushingToViewsChain.cpp +++ b/src/Processors/Transforms/buildPushingToViewsChain.cpp @@ -349,7 +349,7 @@ Chain buildPushingToViewsChain( for (const auto & column : header) { /// But skip columns which storage doesn't have. - if (inner_table_columns.hasPhysical(column.name)) + if (inner_table_columns.hasNotAlias(column.name)) insert_columns.emplace_back(column.name); } diff --git a/src/Storages/ColumnsDescription.cpp b/src/Storages/ColumnsDescription.cpp index 3e098c18776..33d8b309750 100644 --- a/src/Storages/ColumnsDescription.cpp +++ b/src/Storages/ColumnsDescription.cpp @@ -668,6 +668,12 @@ bool ColumnsDescription::hasPhysical(const String & column_name) const it->default_desc.kind != ColumnDefaultKind::Alias && it->default_desc.kind != ColumnDefaultKind::Ephemeral; } +bool ColumnsDescription::hasNotAlias(const String & column_name) const +{ + auto it = columns.get<1>().find(column_name); + return it != columns.get<1>().end() && it->default_desc.kind != ColumnDefaultKind::Alias; +} + bool ColumnsDescription::hasAlias(const String & column_name) const { auto it = columns.get<1>().find(column_name); diff --git a/src/Storages/ColumnsDescription.h b/src/Storages/ColumnsDescription.h index db88c49402a..4de8aa11de3 100644 --- a/src/Storages/ColumnsDescription.h +++ b/src/Storages/ColumnsDescription.h @@ -182,6 +182,7 @@ public: Names getNamesOfPhysical() const; bool hasPhysical(const String & column_name) const; + bool hasNotAlias(const String & column_name) const; bool hasAlias(const String & column_name) const; bool hasColumnOrSubcolumn(GetColumnsOptions::Kind kind, const String & column_name) const; bool hasColumnOrNested(GetColumnsOptions::Kind kind, const String & column_name) const; diff --git a/tests/queries/0_stateless/02933_ephemeral_mv.reference b/tests/queries/0_stateless/02933_ephemeral_mv.reference new file mode 100644 index 00000000000..a77853390d3 --- /dev/null +++ b/tests/queries/0_stateless/02933_ephemeral_mv.reference @@ -0,0 +1,2 @@ +3 3 +42 42 diff --git a/tests/queries/0_stateless/02933_ephemeral_mv.sql b/tests/queries/0_stateless/02933_ephemeral_mv.sql new file mode 100644 index 00000000000..d0725d894f0 --- /dev/null +++ b/tests/queries/0_stateless/02933_ephemeral_mv.sql @@ -0,0 +1,30 @@ + +CREATE TABLE raw +( + name String, + num String +) ENGINE = MergeTree +ORDER BY (name); + +CREATE TABLE parsed_eph +( + name String, + num_ephemeral UInt32 EPHEMERAL, + num UInt32 MATERIALIZED num_ephemeral, +) ENGINE = MergeTree +ORDER BY (name); + +CREATE MATERIALIZED VIEW parse_mv_eph +TO parsed_eph +AS +SELECT + name, + toUInt32(num) as num_ephemeral +FROM raw; + +INSERT INTO raw VALUES ('3', '3'), ('42', '42'); +SELECT name, num FROM parsed_eph; + +DROP VIEW parse_mv_eph; +DROP TABLE parsed_eph; +DROP TABLE raw;