diff --git a/base/poco/CMakeLists.txt b/base/poco/CMakeLists.txt index a4b10013173..434e24cf334 100644 --- a/base/poco/CMakeLists.txt +++ b/base/poco/CMakeLists.txt @@ -4,7 +4,7 @@ add_subdirectory (Data/ODBC) add_subdirectory (Foundation) add_subdirectory (JSON) -if (ENABLE_MONGODB) +if (USE_MONGODB) add_subdirectory(MongoDB) endif() diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 418f515dc4a..4d41184c268 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -155,8 +155,8 @@ add_contrib (datasketches-cpp-cmake datasketches-cpp) add_contrib (incbin-cmake incbin) add_contrib (sqids-cpp-cmake sqids-cpp) -option(ENABLE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) -if (ENABLE_MONGODB) +option(USE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) +if (USE_MONGODB) add_contrib (mongo-c-driver-cmake mongo-c-driver) # requires: zlib add_contrib (mongo-cxx-driver-cmake mongo-cxx-driver) # requires: libmongoc, libbson endif() diff --git a/contrib/mongo-c-driver-cmake/CMakeLists.txt b/contrib/mongo-c-driver-cmake/CMakeLists.txt index 19af1c25ab8..b9ea2a24fc5 100644 --- a/contrib/mongo-c-driver-cmake/CMakeLists.txt +++ b/contrib/mongo-c-driver-cmake/CMakeLists.txt @@ -1,5 +1,5 @@ -option(ENABLE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) -if (NOT ENABLE_MONGODB) +option(USE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) +if (NOT USE_MONGODB) message(STATUS "Not using libmongoc and libbson") return() endif() diff --git a/contrib/mongo-cxx-driver-cmake/CMakeLists.txt b/contrib/mongo-cxx-driver-cmake/CMakeLists.txt index 16526746054..2856e687379 100644 --- a/contrib/mongo-cxx-driver-cmake/CMakeLists.txt +++ b/contrib/mongo-cxx-driver-cmake/CMakeLists.txt @@ -1,6 +1,6 @@ -option(ENABLE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) +option(USE_MONGODB "Enable MongoDB support" ${ENABLE_LIBRARIES}) -if (NOT ENABLE_MONGODB) +if (NOT USE_MONGODB) message(STATUS "Not using mongocxx and bsoncxx") return() endif() diff --git a/programs/local/LocalServer.cpp b/programs/local/LocalServer.cpp index 7a8af6ccafc..fdc17d8f8e3 100644 --- a/programs/local/LocalServer.cpp +++ b/programs/local/LocalServer.cpp @@ -486,6 +486,8 @@ try Poco::ErrorHandler::set(&error_handler); } + processConfig(); + registerInterpreters(); /// Don't initialize DateLUT registerFunctions(); @@ -497,8 +499,6 @@ try registerDisks(/* global_skip_access_check= */ true); registerFormats(); - processConfig(); - SCOPE_EXIT({ cleanup(); }); initTTYBuffer(toProgressOption(getClientConfiguration().getString("progress", "default"))); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1fe28ba5c2..4f5ff82d753 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -412,7 +412,7 @@ dbms_target_link_libraries ( Poco::Redis ) -if (ENABLE_MONGODB) +if (USE_MONGODB) dbms_target_link_libraries (PUBLIC Poco::MongoDB) endif() diff --git a/src/Common/BSONCXXHelper.h b/src/Common/BSONCXXHelper.h index 481c6ed9e3a..93277e69d1e 100644 --- a/src/Common/BSONCXXHelper.h +++ b/src/Common/BSONCXXHelper.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/Common/config.h.in b/src/Common/config.h.in index 6610a032f15..46af4f90c74 100644 --- a/src/Common/config.h.in +++ b/src/Common/config.h.in @@ -64,7 +64,7 @@ #cmakedefine01 USE_LIBARCHIVE #cmakedefine01 USE_POCKETFFT #cmakedefine01 USE_PROMETHEUS_PROTOBUFS -#cmakedefine01 ENABLE_MONGODB +#cmakedefine01 USE_MONGODB #cmakedefine01 USE_NUMACTL /// This is needed for .incbin in assembly. For some reason, include paths don't work there in presence of LTO. diff --git a/src/Dictionaries/CMakeLists.txt b/src/Dictionaries/CMakeLists.txt index d0580648d69..7846a36045b 100644 --- a/src/Dictionaries/CMakeLists.txt +++ b/src/Dictionaries/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries(clickhouse_dictionaries Poco::Redis ) -if (ENABLE_MONGODB) +if (USE_MONGODB) target_link_libraries(clickhouse_dictionaries PRIVATE Poco::MongoDB) endif() diff --git a/src/Dictionaries/MongoDBDictionarySource.cpp b/src/Dictionaries/MongoDBDictionarySource.cpp index fbd49e884f5..4aa71637e08 100644 --- a/src/Dictionaries/MongoDBDictionarySource.cpp +++ b/src/Dictionaries/MongoDBDictionarySource.cpp @@ -1,7 +1,7 @@ #include "config.h" #include "DictionarySourceFactory.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "MongoDBDictionarySource.h" #include "DictionaryStructure.h" @@ -21,7 +21,7 @@ namespace DB namespace ErrorCodes { - #if ENABLE_MONGODB + #if USE_MONGODB extern const int UNSUPPORTED_METHOD; extern const int LOGICAL_ERROR; #else @@ -31,7 +31,7 @@ namespace ErrorCodes void registerDictionarySourceMongoDB(DictionarySourceFactory & factory) { - #if ENABLE_MONGODB + #if USE_MONGODB auto create_dictionary_source = []( const DictionaryStructure & dict_struct, const Poco::Util::AbstractConfiguration & config, @@ -109,7 +109,7 @@ void registerDictionarySourceMongoDB(DictionarySourceFactory & factory) factory.registerSource("mongodb", create_dictionary_source); } -#if ENABLE_MONGODB +#if USE_MONGODB static const UInt64 max_block_size = 8192; diff --git a/src/Dictionaries/MongoDBDictionarySource.h b/src/Dictionaries/MongoDBDictionarySource.h index ee6c16e7066..45f22e8908f 100644 --- a/src/Dictionaries/MongoDBDictionarySource.h +++ b/src/Dictionaries/MongoDBDictionarySource.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "DictionaryStructure.h" #include "IDictionarySource.h" diff --git a/src/Dictionaries/MongoDBPocoLegacyDictionarySource.cpp b/src/Dictionaries/MongoDBPocoLegacyDictionarySource.cpp index 7f741a06fc7..25fa73d089d 100644 --- a/src/Dictionaries/MongoDBPocoLegacyDictionarySource.cpp +++ b/src/Dictionaries/MongoDBPocoLegacyDictionarySource.cpp @@ -1,7 +1,7 @@ #include "config.h" #include "DictionarySourceFactory.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "MongoDBPocoLegacyDictionarySource.h" #include "DictionaryStructure.h" #include "registerDictionaries.h" @@ -14,7 +14,7 @@ namespace DB namespace ErrorCodes { -#if ENABLE_MONGODB +#if USE_MONGODB extern const int NOT_IMPLEMENTED; extern const int UNSUPPORTED_METHOD; extern const int MONGODB_CANNOT_AUTHENTICATE; @@ -23,14 +23,14 @@ extern const int SUPPORT_IS_DISABLED; #endif } -#if ENABLE_MONGODB +#if USE_MONGODB static const std::unordered_set dictionary_allowed_keys = { "host", "port", "user", "password", "db", "database", "uri", "collection", "name", "method", "options"}; #endif void registerDictionarySourceMongoDBPocoLegacy(DictionarySourceFactory & factory) { - #if ENABLE_MONGODB + #if USE_MONGODB auto create_mongo_db_dictionary = []( const DictionaryStructure & dict_struct, const Poco::Util::AbstractConfiguration & config, @@ -92,7 +92,7 @@ void registerDictionarySourceMongoDBPocoLegacy(DictionarySourceFactory & factory } -#if ENABLE_MONGODB +#if USE_MONGODB #include #include #include diff --git a/src/Dictionaries/MongoDBPocoLegacyDictionarySource.h b/src/Dictionaries/MongoDBPocoLegacyDictionarySource.h index 0c023e34d34..95dc1194981 100644 --- a/src/Dictionaries/MongoDBPocoLegacyDictionarySource.h +++ b/src/Dictionaries/MongoDBPocoLegacyDictionarySource.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/Processors/Sources/MongoDBPocoLegacySource.cpp b/src/Processors/Sources/MongoDBPocoLegacySource.cpp index d14f8e645c0..43d04527800 100644 --- a/src/Processors/Sources/MongoDBPocoLegacySource.cpp +++ b/src/Processors/Sources/MongoDBPocoLegacySource.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "MongoDBPocoLegacySource.h" #include diff --git a/src/Processors/Sources/MongoDBPocoLegacySource.h b/src/Processors/Sources/MongoDBPocoLegacySource.h index 9ce72541124..0c9f2c7cc9f 100644 --- a/src/Processors/Sources/MongoDBPocoLegacySource.h +++ b/src/Processors/Sources/MongoDBPocoLegacySource.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/Processors/Sources/MongoDBSource.cpp b/src/Processors/Sources/MongoDBSource.cpp index 31fe315102f..f593f36a318 100644 --- a/src/Processors/Sources/MongoDBSource.cpp +++ b/src/Processors/Sources/MongoDBSource.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "MongoDBSource.h" #include diff --git a/src/Processors/Sources/MongoDBSource.h b/src/Processors/Sources/MongoDBSource.h index b08a46f3dd9..5e64563a239 100644 --- a/src/Processors/Sources/MongoDBSource.h +++ b/src/Processors/Sources/MongoDBSource.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include #include diff --git a/src/Storages/StorageMongoDB.cpp b/src/Storages/StorageMongoDB.cpp index 7308c7c642a..437beee9458 100644 --- a/src/Storages/StorageMongoDB.cpp +++ b/src/Storages/StorageMongoDB.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include @@ -182,7 +182,11 @@ std::string mongoFuncName(const std::string & func) } template -std::optional StorageMongoDB::visitWhereFunction(const ContextPtr & context, const FunctionNode * func, OnError on_error) +std::optional StorageMongoDB::visitWhereFunction( + const ContextPtr & context, + const FunctionNode * func, + const JoinNode * join_node, + OnError on_error) { if (func->getArguments().getNodes().empty()) return {}; @@ -197,6 +201,8 @@ std::optional StorageMongoDB::visitWhereFunction(const // Skip columns from other tables in JOIN queries. if (table->getStorage()->getStorageID() != this->getStorageID()) return {}; + if (join_node && column->getColumnSource() != join_node->getLeftTableExpression()) + return {}; // Only these function can have exactly one argument and be passed to MongoDB. if (func->getFunctionName() == "isNull") @@ -236,7 +242,7 @@ std::optional StorageMongoDB::visitWhereFunction(const } if (const auto & func_value = value->as()) - if (const auto & res_value = visitWhereFunction(context, func_value, on_error); res_value.has_value()) + if (const auto & res_value = visitWhereFunction(context, func_value, join_node, on_error); res_value.has_value()) return make_document(kvp(column->getColumnName(), make_document(kvp(func_name, *res_value)))); } } @@ -246,7 +252,7 @@ std::optional StorageMongoDB::visitWhereFunction(const for (const auto & elem : func->getArguments().getNodes()) { if (const auto & elem_func = elem->as()) - if (const auto & res_value = visitWhereFunction(context, elem_func, on_error); res_value.has_value()) + if (const auto & res_value = visitWhereFunction(context, elem_func, join_node, on_error); res_value.has_value()) arr.append(*res_value); } if (!arr.view().empty()) @@ -308,8 +314,8 @@ bsoncxx::document::value StorageMongoDB::buildMongoDBQuery(const ContextPtr & co if (throw_on_error) throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Only simple queries are supported, failed to convert expression '{}' to MongoDB query. " - "You can disable this restriction with 'SET mongodb_throw_on_unsupported_query=0', to read the full table and process on CLickHouse side (this may cause poor performance)", node->formatASTForErrorMessage()); - LOG_WARNING(log, "Failed to build MongoDB sort for '{}'", node ? node->formatASTForErrorMessage() : ""); + "You can disable this restriction with 'SET mongodb_throw_on_unsupported_query=0', to read the full table and process on ClickHouse side (this may cause poor performance)", node->formatASTForErrorMessage()); + LOG_WARNING(log, "Failed to build MongoDB query for '{}'", node ? node->formatASTForErrorMessage() : ""); }; @@ -365,14 +371,14 @@ bsoncxx::document::value StorageMongoDB::buildMongoDBQuery(const ContextPtr & co { std::optional filter{}; if (const auto & func = query_tree.getWhere()->as()) - filter = visitWhereFunction(context, func, on_error); + filter = visitWhereFunction(context, func, join_node, on_error); else if (const auto & const_expr = query_tree.getWhere()->as()) { if (const_expr->hasSourceExpression()) { if (const auto & func_expr = const_expr->getSourceExpression()->as()) - filter = visitWhereFunction(context, func_expr, on_error); + filter = visitWhereFunction(context, func_expr, join_node, on_error); } } @@ -381,7 +387,6 @@ bsoncxx::document::value StorageMongoDB::buildMongoDBQuery(const ContextPtr & co LOG_DEBUG(log, "MongoDB query has built: '{}'.", bsoncxx::to_json(*filter)); return std::move(*filter); } - on_error(query_tree.getWhere().get()); } else on_error(join_node); diff --git a/src/Storages/StorageMongoDB.h b/src/Storages/StorageMongoDB.h index a242b7099fd..644b0d627dd 100644 --- a/src/Storages/StorageMongoDB.h +++ b/src/Storages/StorageMongoDB.h @@ -2,9 +2,9 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB +#include #include - #include #include @@ -61,8 +61,17 @@ public: private: template - std::optional visitWhereFunction(const ContextPtr & context, const FunctionNode * func, OnError on_error); - bsoncxx::document::value buildMongoDBQuery(const ContextPtr & context, mongocxx::options::find & options, const SelectQueryInfo & query, const Block & sample_block); + std::optional visitWhereFunction( + const ContextPtr & context, + const FunctionNode * func, + const JoinNode * join_node, + OnError on_error); + + bsoncxx::document::value buildMongoDBQuery( + const ContextPtr & context, + mongocxx::options::find & options, + const SelectQueryInfo & query, + const Block & sample_block); const MongoDBConfiguration configuration; LoggerPtr log; diff --git a/src/Storages/StorageMongoDBPocoLegacy.cpp b/src/Storages/StorageMongoDBPocoLegacy.cpp index a40d2eb36c1..7d7b84f10bf 100644 --- a/src/Storages/StorageMongoDBPocoLegacy.cpp +++ b/src/Storages/StorageMongoDBPocoLegacy.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include #include diff --git a/src/Storages/StorageMongoDBPocoLegacy.h b/src/Storages/StorageMongoDBPocoLegacy.h index 6037a9b0886..a5814ccd5dd 100644 --- a/src/Storages/StorageMongoDBPocoLegacy.h +++ b/src/Storages/StorageMongoDBPocoLegacy.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/Storages/StorageMongoDBPocoLegacySocketFactory.cpp b/src/Storages/StorageMongoDBPocoLegacySocketFactory.cpp index d35940ef16e..bcfe995dcc6 100644 --- a/src/Storages/StorageMongoDBPocoLegacySocketFactory.cpp +++ b/src/Storages/StorageMongoDBPocoLegacySocketFactory.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include "StorageMongoDBPocoLegacySocketFactory.h" #include diff --git a/src/Storages/StorageMongoDBPocoLegacySocketFactory.h b/src/Storages/StorageMongoDBPocoLegacySocketFactory.h index d5f5d43327e..ee6ee8faa29 100644 --- a/src/Storages/StorageMongoDBPocoLegacySocketFactory.h +++ b/src/Storages/StorageMongoDBPocoLegacySocketFactory.h @@ -2,7 +2,7 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include diff --git a/src/Storages/registerStorages.cpp b/src/Storages/registerStorages.cpp index 1cbf54a20df..1b2b1e51317 100644 --- a/src/Storages/registerStorages.cpp +++ b/src/Storages/registerStorages.cpp @@ -61,7 +61,7 @@ void registerStorageJDBC(StorageFactory & factory); void registerStorageMySQL(StorageFactory & factory); #endif -#if ENABLE_MONGODB +#if USE_MONGODB void registerStorageMongoDB(StorageFactory & factory); void registerStorageMongoDBPocoLegacy(StorageFactory & factory); #endif @@ -165,7 +165,7 @@ void registerStorages(bool use_legacy_mongodb_integration [[maybe_unused]]) registerStorageMySQL(factory); #endif - #if ENABLE_MONGODB + #if USE_MONGODB if (use_legacy_mongodb_integration) registerStorageMongoDBPocoLegacy(factory); else diff --git a/src/TableFunctions/TableFunctionMongoDB.cpp b/src/TableFunctions/TableFunctionMongoDB.cpp index 4d762019e6a..489a9933d75 100644 --- a/src/TableFunctions/TableFunctionMongoDB.cpp +++ b/src/TableFunctions/TableFunctionMongoDB.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/TableFunctions/TableFunctionMongoDBPocoLegacy.cpp b/src/TableFunctions/TableFunctionMongoDBPocoLegacy.cpp index f1e602257b5..eafb756061a 100644 --- a/src/TableFunctions/TableFunctionMongoDBPocoLegacy.cpp +++ b/src/TableFunctions/TableFunctionMongoDBPocoLegacy.cpp @@ -1,6 +1,6 @@ #include "config.h" -#if ENABLE_MONGODB +#if USE_MONGODB #include #include diff --git a/src/TableFunctions/registerTableFunctions.cpp b/src/TableFunctions/registerTableFunctions.cpp index caa358866d7..dc08eb5cbe1 100644 --- a/src/TableFunctions/registerTableFunctions.cpp +++ b/src/TableFunctions/registerTableFunctions.cpp @@ -22,7 +22,7 @@ void registerTableFunctions(bool use_legacy_mongodb_integration [[maybe_unused]] registerTableFunctionValues(factory); registerTableFunctionInput(factory); registerTableFunctionGenerate(factory); -#if ENABLE_MONGODB +#if USE_MONGODB if (use_legacy_mongodb_integration) registerTableFunctionMongoDBPocoLegacy(factory); else diff --git a/src/TableFunctions/registerTableFunctions.h b/src/TableFunctions/registerTableFunctions.h index d330af989e1..d5dc89f601d 100644 --- a/src/TableFunctions/registerTableFunctions.h +++ b/src/TableFunctions/registerTableFunctions.h @@ -20,7 +20,7 @@ void registerTableFunctionURLCluster(TableFunctionFactory & factory); void registerTableFunctionValues(TableFunctionFactory & factory); void registerTableFunctionInput(TableFunctionFactory & factory); void registerTableFunctionGenerate(TableFunctionFactory & factory); -#if ENABLE_MONGODB +#if USE_MONGODB void registerTableFunctionMongoDB(TableFunctionFactory & factory); void registerTableFunctionMongoDBPocoLegacy(TableFunctionFactory & factory); #endif diff --git a/src/configure_config.cmake b/src/configure_config.cmake index 57b20c82aab..03c30a0cd5c 100644 --- a/src/configure_config.cmake +++ b/src/configure_config.cmake @@ -174,7 +174,7 @@ if (TARGET ch_contrib::prometheus_protobufs) set(USE_PROMETHEUS_PROTOBUFS 1) endif() if (TARGET ch_contrib::mongocxx) - set(ENABLE_MONGODB 1) + set(USE_MONGODB 1) endif() if (TARGET ch_contrib::numactl) set(USE_NUMACTL 1)