Repository navigation
Fix mongodb table function: accept key-value overrides for named collections (database, collection, options) - #89616
Conversation
|
Workflow [PR], commit [a7533e5] Summary: ❌
|
|
@GrigoryPervakov I don't get why the recent tests keep on failing. I tried syncing the repos several times which changed the failure reasons. I wonder if I should change anything at all and wait or I'm just not able to find the issue in my edits. |
GrigoryPervakov
left a comment
There was a problem hiding this comment.
Good overall. But need to improve docstrings
| @@ -131,6 +148,7 @@ void registerTableFunctionMongoDB(TableFunctionFactory & factory) | |||
| .examples = { | |||
| {"Fetch collection by URI", "SELECT * FROM mongodb('mongodb://root:clickhouse@localhost:27017/database', 'example_collection', 'key UInt64, data String')", ""}, | |||
| {"Fetch collection over TLS", "SELECT * FROM mongodb('localhost:27017', 'database', 'example_collection', 'root', 'clickhouse', 'key UInt64, data String', 'tls=true')", ""}, | |||
| {"Fetch collection over TLS", "SELECT * FROM mongodb(host='localhost', port='27017', database='database', collection='example_collection', user='root', password='clickhouse', structure='key UInt64, data String', options='tls=true')", ""}, | |||
There was a problem hiding this comment.
nit: Copy-paste example name.
Let's add examples with named collections and overrides
There was a problem hiding this comment.
sorry for the late response. they've cut the internet connection a few weeks ago, I might not be able to do anything for an unknown period. please take care of the world.
There was a problem hiding this comment.
sorry for the late response. they've cut the internet connection a few weeks ago, I might not be able to do anything for an unknown period. please take care of the world.
|
@GrigoryPervakov It seems to have passed all the tests. |
Yes, please do not update the branch. I want to look at the PR with the finished pipeline 😁 |
|
… like the engine and improve error messaging
fixed passing all arguments without arg_name
fixed test connection to mongo_db
removed duplicated empty line in docs
Enhanced error messages.
added named collection without override test
fixed names
bd90e97 to
c05e98a
Compare
c05e98a to
1d5100f
Compare
7a277ed
`check_named_collection_dependencies` makes `DROP NAMED COLLECTION` throw `NAMED_COLLECTION_IS_USED` only for tables that registered a dependency, and a table engine registers by passing its `StorageID` to `tryGetNamedCollectionWithOverrides`. `StorageMongoDB`'s `getConfigurationImpl` had `table_id` in scope but did not pass it: ClickHouse#96181 added the argument in 2311e59, and its branch merge 468aaca with ClickHouse#89616 (which rewrote the function) kept master's line without it. Every other table engine passes its id. So the drop succeeded under a live MongoDB table, the table could not be attached on the next restart (669), its database became unusable, and with `async_load_databases = 0` the server did not start. The new line is identical to the hunk in ClickHouse#112805. `05315_mongodb_connection_options_secrets` (ClickHouse#123240) dropped its two collections while `e06`, `e07` and `e08` still used them. Stateless CI drops the test database, but Stress keeps it and restarts the server, so master Stress jobs failed with `Cannot start clickhouse-server`. The test now expects the drop to be refused while the tables exist, drops the tables first, and pins `ast_fuzzer_any_query = 0` on every statement that names a collection: the stress profile fuzzes DDL, and a fuzzed `DETACH` of such a table hides it from the catalog, so its dependency is pruned and the collection drop succeeds (the generic detached-table hole, ClickHouse#121519); `__fuzz_N` clones would otherwise also hold the collection and make the final drop fail. Not changed: table functions (`CREATE TABLE ... AS mongodb(nc)`) register no dependency for any engine except `bigquery`; the experimental `MaterializedPostgreSQL` engine has the same omission. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
mongodb()table function with a named collection plus key-value overrides (for exampledatabase = '...'orcollection = '...') resulted in a BAD_ARGUMENTS error. The table-function parsing previously only accepted a small allow-list of key names and rejected other valid overrides.TableFunctionMongoDBand forwards overrides (except the specialstructureargument) to the storage configuration code, which already validates and consumes keys such asdatabase,collection,options, andoid_columns.Motivation and background
databaseorcollectionwithout duplicating credentials/config.DB::Exception: Expected key-value defined argument, got collection = 'collection_name'. (BAD_ARGUMENTS)
What changed (technical)
getKeyValueMongoDBArgumentnow returns any key-value pair (after verifying the AST isequals(key, value)), instead of rejecting unknown keys.TableFunctionMongoDB::parseArgumentsstill treatsstructurespecially (it must be a literal), but forwards any other key-value AST node intomain_arguments. Those arguments are passed unchanged toStorageMongoDB::getConfiguration, where existing validation and URI construction take place.test_named_collection_overrideswhich demonstrates using a named collection and overridingdatabaseandcollectioninline, asserting the query succeeds and returns expected results.Files changed
Behavioral / compatibility notes
structureremains a special literal argument and continues to be parsed by the table function layer.How to reproduce the original bug (before this change)
SELECT _id
FROM mongodb(
named_collection_mongo_cred,
structure = '_id String',
collection = 'collection_name',
database = 'db_name_alt'
)
DB::Exception: Expected key-value defined argument, got collection = 'collection_name'. (BAD_ARGUMENTS)
Test coverage
SELECT sum(key) FROM mongodb(mongo1, database = 'override_db', collection = 'override_collection', structure='key UInt64, data String') == "3"
How to run the added test locally
(These tests require the repository's test harness; use the same environment that CI uses.)
Changelog entry (short)
Suggested commit message
Risk and mitigations
StorageMongoDB::getConfiguration. The integration test covers the core scenario.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow key-value overrides for named collection parameters in mongodb table function.
Version info
26.2.1.627