From e595df05d90e4b4ecb8419ef81d2400fa29d8f63 Mon Sep 17 00:00:00 2001 From: Ivan <5627721+abyss7@users.noreply.github.com> Date: Thu, 17 Oct 2019 14:12:35 +0300 Subject: [PATCH] Fix CREATE TABLE AS from table with virtual columns (#7183) * Disable undefined instrumentation for rdkafka --- contrib/librdkafka-cmake/CMakeLists.txt | 1 + .../Interpreters/InterpreterCreateQuery.cpp | 4 +++ dbms/src/Storages/IStorage.h | 3 ++- ...nce => 00981_no_virtual_columns.reference} | 1 + .../0_stateless/00981_no_virtual_columns.sql | 26 +++++++++++++++++++ ...1_no_virtual_columns_in_system_columns.sql | 13 ---------- 6 files changed, 34 insertions(+), 14 deletions(-) rename dbms/tests/queries/0_stateless/{00981_no_virtual_columns_in_system_columns.reference => 00981_no_virtual_columns.reference} (50%) create mode 100644 dbms/tests/queries/0_stateless/00981_no_virtual_columns.sql delete mode 100644 dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.sql diff --git a/contrib/librdkafka-cmake/CMakeLists.txt b/contrib/librdkafka-cmake/CMakeLists.txt index 64dc83fa8b6..fc1ba23f7c1 100644 --- a/contrib/librdkafka-cmake/CMakeLists.txt +++ b/contrib/librdkafka-cmake/CMakeLists.txt @@ -62,6 +62,7 @@ set(SRCS ) add_library(rdkafka ${SRCS}) +target_compile_options(rdkafka PRIVATE -fno-sanitize=undefined) target_include_directories(rdkafka SYSTEM PUBLIC include) target_include_directories(rdkafka SYSTEM PUBLIC ${RDKAFKA_SOURCE_DIR}) # Because weird logic with "include_next" is used. target_include_directories(rdkafka SYSTEM PRIVATE ${ZSTD_INCLUDE_DIR}/common) # Because wrong path to "zstd_errors.h" is used. diff --git a/dbms/src/Interpreters/InterpreterCreateQuery.cpp b/dbms/src/Interpreters/InterpreterCreateQuery.cpp index d187f68eda3..8913f6a4b12 100644 --- a/dbms/src/Interpreters/InterpreterCreateQuery.cpp +++ b/dbms/src/Interpreters/InterpreterCreateQuery.cpp @@ -203,6 +203,10 @@ ASTPtr InterpreterCreateQuery::formatColumns(const ColumnsDescription & columns) for (const auto & column : columns) { + /// Do not include virtual columns + if (column.is_virtual) + continue; + const auto column_declaration = std::make_shared(); ASTPtr column_declaration_ptr{column_declaration}; diff --git a/dbms/src/Storages/IStorage.h b/dbms/src/Storages/IStorage.h index ced109922dc..8d30f31bde3 100644 --- a/dbms/src/Storages/IStorage.h +++ b/dbms/src/Storages/IStorage.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,7 @@ struct ColumnSize * - data storage structure (compression, etc.) * - concurrent access to data (locks, etc.) */ -class IStorage : public std::enable_shared_from_this +class IStorage : public std::enable_shared_from_this, public TypePromotion { public: IStorage() = default; diff --git a/dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.reference b/dbms/tests/queries/0_stateless/00981_no_virtual_columns.reference similarity index 50% rename from dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.reference rename to dbms/tests/queries/0_stateless/00981_no_virtual_columns.reference index a7ec77dc030..c1df99e5f94 100644 --- a/dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.reference +++ b/dbms/tests/queries/0_stateless/00981_no_virtual_columns.reference @@ -1 +1,2 @@ default merge_ab x UInt8 0 0 0 0 0 0 0 +default as_kafka x UInt8 0 0 0 0 0 0 0 diff --git a/dbms/tests/queries/0_stateless/00981_no_virtual_columns.sql b/dbms/tests/queries/0_stateless/00981_no_virtual_columns.sql new file mode 100644 index 00000000000..43c08b71b97 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00981_no_virtual_columns.sql @@ -0,0 +1,26 @@ +DROP TABLE IF EXISTS merge_a; +DROP TABLE IF EXISTS merge_b; +DROP TABLE IF EXISTS merge_ab; +DROP TABLE IF EXISTS kafka; +DROP TABLE IF EXISTS as_kafka; + +CREATE TABLE merge_a (x UInt8) ENGINE = StripeLog; +CREATE TABLE merge_b (x UInt8) ENGINE = StripeLog; +CREATE TABLE merge_ab AS merge(currentDatabase(), '^merge_[ab]$'); + +CREATE TABLE kafka (x UInt8) + ENGINE = Kafka + SETTINGS kafka_broker_list = 'kafka', + kafka_topic_list = 'topic', + kafka_group_name = 'group', + kafka_format = 'CSV'; +CREATE TABLE as_kafka AS kafka ENGINE = Memory; + +SELECT * FROM system.columns WHERE database = currentDatabase() AND table = 'merge_ab'; +SELECT * FROM system.columns WHERE database = currentDatabase() AND table = 'as_kafka'; + +DROP TABLE merge_a; +DROP TABLE merge_b; +DROP TABLE merge_ab; +DROP TABLE kafka; +DROP TABLE as_kafka; diff --git a/dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.sql b/dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.sql deleted file mode 100644 index 476377b4ddf..00000000000 --- a/dbms/tests/queries/0_stateless/00981_no_virtual_columns_in_system_columns.sql +++ /dev/null @@ -1,13 +0,0 @@ -DROP TABLE IF EXISTS merge_a; -DROP TABLE IF EXISTS merge_b; -DROP TABLE IF EXISTS merge_ab; - -CREATE TABLE merge_a (x UInt8) ENGINE = StripeLog; -CREATE TABLE merge_b (x UInt8) ENGINE = StripeLog; -CREATE TABLE merge_ab AS merge(currentDatabase(), '^merge_[ab]$'); - -SELECT * FROM system.columns WHERE database = currentDatabase() AND table = 'merge_ab'; - -DROP TABLE merge_a; -DROP TABLE merge_b; -DROP TABLE merge_ab;