diff --git a/src/Storages/StorageMerge.h b/src/Storages/StorageMerge.h index 7258f9cebaf..20460e95156 100644 --- a/src/Storages/StorageMerge.h +++ b/src/Storages/StorageMerge.h @@ -49,7 +49,7 @@ public: const ASTPtr & left_in_operand, ContextPtr query_context, const StorageMetadataPtr & metadata_snapshot) const override; private: - using DbToTableSetMap = std::unordered_map>; + using DbToTableSetMap = std::map>; std::optional source_database_regexp; std::optional source_table_regexp; diff --git a/src/TableFunctions/TableFunctionMerge.cpp b/src/TableFunctions/TableFunctionMerge.cpp index 7a905bf2ae7..40d0d1b7921 100644 --- a/src/TableFunctions/TableFunctionMerge.cpp +++ b/src/TableFunctions/TableFunctionMerge.cpp @@ -106,9 +106,12 @@ ColumnsDescription TableFunctionMerge::getActualTableStructure(ContextPtr contex { for (const auto & db_with_tables : getSourceDatabasesAndTables(context)) { - auto storage = DatabaseCatalog::instance().tryGetTable(StorageID{db_with_tables.first, *db_with_tables.second.begin()}, context); - if (storage) - return ColumnsDescription{storage->getInMemoryMetadataPtr()->getColumns().getAllPhysical()}; + for (const auto & table : db_with_tables.second) + { + auto storage = DatabaseCatalog::instance().tryGetTable(StorageID{db_with_tables.first, table}, context); + if (storage) + return ColumnsDescription{storage->getInMemoryMetadataPtr()->getColumns().getAllPhysical()}; + } } throwNoTablesMatchRegexp(source_database_name_or_regexp, source_table_regexp); @@ -130,7 +133,7 @@ StoragePtr TableFunctionMerge::executeImpl(const ASTPtr & /*ast_function*/, Cont return res; } -NameSet +TableFunctionMerge::TableSet TableFunctionMerge::getMatchedTablesWithAccess(const String & database_name, const String & table_regexp, const ContextPtr & context) { OptimizedRegularExpression table_re(table_regexp); @@ -144,7 +147,7 @@ TableFunctionMerge::getMatchedTablesWithAccess(const String & database_name, con bool granted_show_on_all_tables = access->isGranted(AccessType::SHOW_TABLES, database_name); bool granted_select_on_all_tables = access->isGranted(AccessType::SELECT, database_name); - NameSet tables; + TableSet tables; for (auto it = database->getTablesIterator(context, table_name_match); it->isValid(); it->next()) { diff --git a/src/TableFunctions/TableFunctionMerge.h b/src/TableFunctions/TableFunctionMerge.h index 438221ed95e..73b61f8eb79 100644 --- a/src/TableFunctions/TableFunctionMerge.h +++ b/src/TableFunctions/TableFunctionMerge.h @@ -20,11 +20,12 @@ private: StoragePtr executeImpl(const ASTPtr & ast_function, ContextPtr context, const std::string & table_name, ColumnsDescription cached_columns) const override; const char * getStorageTypeName() const override { return "Merge"; } - using DbToTableSetMap = std::unordered_map>; + using TableSet = std::set; + using DbToTableSetMap = std::map; const DbToTableSetMap & getSourceDatabasesAndTables(ContextPtr context) const; ColumnsDescription getActualTableStructure(ContextPtr context) const override; void parseArguments(const ASTPtr & ast_function, ContextPtr context) override; - static NameSet getMatchedTablesWithAccess(const String & database_name, const String & table_regexp, const ContextPtr & context); + static TableSet getMatchedTablesWithAccess(const String & database_name, const String & table_regexp, const ContextPtr & context); String source_database_name_or_regexp; String source_table_regexp; diff --git a/tests/queries/0_stateless/00717_merge_and_distributed.reference b/tests/queries/0_stateless/00717_merge_and_distributed.reference index ec6c2725a2a..073df56d693 100644 --- a/tests/queries/0_stateless/00717_merge_and_distributed.reference +++ b/tests/queries/0_stateless/00717_merge_and_distributed.reference @@ -49,9 +49,9 @@ 2018-08-01 100 2018-08-01 200 --------------Implicit type conversion------------ +2018-08-01 -1 +2018-08-01 1 +2018-08-01 -1 2018-08-01 1 -2018-08-01 18446744073709551615 -2018-08-01 1 -2018-08-01 18446744073709551615 2018-08-01 1 2018-08-01 1