Repository navigation
Conversation
e2d1ebd to
94f7120
Compare
|
Workflow [PR], commit [beaf54a] Summary: ❌
AI ReviewSummaryAdds an experimental MongoDB endpoint and query dialect. Reviewed head The new scalar Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Fix the five active correctness findings and add the focused regressions. Resolve the deferred mutation-overflow behavior safely before approval; the capture-group limitation remains a separate documented concern. |
|
All the findings of the AI review are addressed. Where a finding is fixed, the fix is listed with the test that covers it. Blockers
Majors
CI
Documentation: added Changelog: the category is now Two notes on behaviour that the findings did not cover but the requested tests made visible: |
|
Running the new wire protocol tests against a server found one more real bug, now fixed in All 14 tests of |
…ly built `Fast test` configures with `-DENABLE_RAPIDJSON=1`, but it also initializes only the submodules listed in `ci/jobs/fast_test.py`, and `contrib/rapidjson` was not one of them. `add_contrib` returns early for an empty submodule directory, so `ch_contrib::rapidjson` never existed, `USE_RAPIDJSON` stayed `0`, and `src/Parsers/Mongo` was dropped from the build. `03214_mongo_queries` and `04628_mongo_dialect_qualified_collection` then failed with `SYNTAX_ERROR: failed at position 1 (db)`, because the client fell back to the ClickHouse parser instead of the Mongo one. Add the submodule, and make that fallback impossible to hit silently: `ClientBase` and `LocalConnection` now throw `SUPPORT_IS_DISABLED` for `dialect = 'mongo'` in a build without rapidjson, the same as `executeQuery` already did. Parsing a Mongo query as ClickHouse SQL only produced a confusing syntax error that pointed at the query rather than at the build. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=68493&sha=1252a7414ba8acf66e47253ee3f1193660169d98&name_0=PR&name_1=Fast%20test ClickHouse#68493 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`cpp`:
- `getRapidJsonRepresentation` and `getJson` are renamed to
`getRapidJSONRepresentation` and `getJSON`, since an abbreviation has to be in all
caps.
- `splitByNewline` used `std::stringstream`; it reads through `ReadBufferFromString`
now. The result is the same for every input, including an empty string, a missing
trailing newline and an empty line in the middle.
- Remove the extra empty lines in `ParserMongoOrderBy.cpp`.
`catch_all`: the two `catch (...)` blocks of `handle` turned any failure of a Mongo
command into the `{"errmsg": ..., "ok": 0}` reply and left no trace on the server, so
the reason a command failed was only visible to the client. They call
`tryLogCurrentException` now.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=68493&sha=1252a7414ba8acf66e47253ee3f1193660169d98&name_0=PR&name_1=Style%20check
ClickHouse#68493
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… operand, fold a `Dynamic` sum in order, promote `$multiply` like Mongo Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reter does, a temporary table included Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e check Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
New tests: Two threads are still open and need a human decision, as explained in them:
|
… output The `$rename` case filtered the client output with `^[0-9].*` to keep the selected row, which also kept the frames of the stack trace that the Fast test prints with the error, so the test failed with "having exception in stdout". Keep only the name of the error and a row of two numbers. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=68493&sha=c0b57832f72b6b4930dba3c65d28eca588470ed3&name_0=PR&name_1=Fast%20test ClickHouse#68493 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With parallel replicas, a read of a temporary table logs a warning that the other replicas do not have it, and the test failed on the output in stderr. Only errors are sent to the client by the queries on the temporary table now. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=68493&sha=9463c56fac224155de640b881e16130d63a60d51&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 ClickHouse#68493 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mporary table updates - `$add` and `$subtract` reject a date held by a `Dynamic` operand in each row, as they reject a date operand. - `$divide` rejects a decimal held by a `Dynamic` operand, whose quotient would keep the scale of the dividend. - `$pow` rejects a decimal held by a `Dynamic` operand, and a power of integers held by it that a `Float64` may not hold exactly; zero raised to a negative exponent is an error, as in Mongo, instead of an infinity. - `makeIsDecimal` accepts `LowCardinality`, as `makeIsAccumulatedNumber` does. - `$not` rejects a constant, also one written in Extended JSON, and an empty document, instead of taking it as a negated equality. - The statements of the wire protocol run with every `*_overflow_mode` set to `throw`, so a limit of the profile fails the command instead of returning a cut result with an exhausted cursor. - The access check of a Mongo update resolves the table as the reading of its columns does, so an update of a temporary table is checked against it, not against a namesake in the current database. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
Two threads stay open for a human decision, as explained there:
|
| } | ||
|
|
||
| /// Mongo drops a document whose array is empty or missing, which is what an inner `ARRAY JOIN` does. | ||
| chain.array_join = makeArrayJoin(std::move(expressions)); |
There was a problem hiding this comment.
❌ Blocker: MongoDB allows $unwind on a non-array value too: when the field is present, non-null, and not an empty array, the stage must emit that document once with the value unchanged (and includeArrayIndex is null for the non-array case). Here both branches still route the path through ARRAY JOIN, so a valid pipeline such as [{"$unwind":"$name"}] on name String reaches ARRAY JOIN of not array nor map instead.
The preserving branch has the same static-array assumption in translateUnwindPreservingEmpty, so this is not limited to the non-preserving form. Please special-case non-array inputs instead of lowering every path through ARRAY JOIN.
There was a problem hiding this comment.
🕵 Not fixed: this needs a human decision. The translation does not know the column type, and SQL cannot pick a for an array column and [a] for any other column. if/multiIf need a common supertype of Array(T) and T, even with a constant condition. arrayFlatten([a]) wraps a scalar correctly but flattens an array of arrays through every level, which would unwind [[1, 2], [3]] into 1, 2, 3 instead of [1, 2], [3]. A faithful fix needs either the schema at translation time (the wire handler could read system.columns before translating) or a new function such as arrayWrapIfNotArray. Either is a separate design change. [{"$unwind": "$name"}] on a String column is still rejected (ARRAY JOIN of not array nor map), not answered wrongly. In 35e6be994e7e, docs/concepts/features/interfaces/mongo.mdx documents that $unwind requires a field of an array type. I am leaving this thread open for a decision on which approach to take.
There was a problem hiding this comment.
🕵 Fixed in beaf54a04dd3, without a new function and without reading the schema at translation time. A field that is not an array is now unwound into itself: the document is kept once with the field and its type unchanged and a null includeArrayIndex, and it is dropped when the field is null unless preserveNullAndEmptyArrays is set.
The array to join is chosen by a constant condition on toTypeName of the field. A plain if needs a common type of Array(T) and T, so the choice is written as nested if functions whose unselected branches name a column that does not exist (the __mongo_ prefix is reserved). The analyzer replaces an if of a constant condition with the selected branch when the other branch cannot be analyzed, the same way if(hasColumnInTable(...), column, default) works, so only the selected branch decides the type. Both forms of $unwind share one translation now, so the preserving one is covered too.
A Dynamic or a Variant column can hold an array in one row and another value in the next, so the type cannot decide it; such a column is still rejected rather than kept in one piece. The docs say so.
Tests: the new 05872_mongo_dialect_unwind_of_a_field_that_is_not_an_array (string, number, LowCardinality, Nullable, index, preserving form, array of arrays, Dynamic), and test_aggregate in test_mongo_protocol now checks the wire result instead of an error.
There was a problem hiding this comment.
[Blocker] The non-array fix still sends Map values through the array path at src/Parsers/Mongo/ParserMongoAggregateQuery.cpp:852-853. For an existing t(m Map(String, Int32)) containing map('a', 1, 'b', 2), db.t.aggregate([{"$unwind":"$m"}]) produces two rows of key/value tuples instead of keeping the original document once. An empty map drops the row entirely. appendTypedValue encodes a Map as a BSON document (src/Core/Mongo/Handler.cpp:559-570), but getArrayJoinDataType converts it into Array(Tuple(...)) (src/Interpreters/ArrayJoinAction.cpp:35-39), so this is still a non-array value being unwound. Route Map through the single-value branch and cover a populated and an empty map, including includeArrayIndex.
The condition of `$expr` in a `find` is evaluated for every row of a block
read, not only for the rows the condition on `id` selects. So the query that
expected `{"id":2}` also evaluated `$divide` on the date and the decimal rows
of the same table and failed with `ILLEGAL_TYPE_OF_ARGUMENT` or the decimal
`throwIf`, which ended up in stderr. The queries with `$expr` now read tables
that hold a single kind of value.
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=68493&sha=14cdc63206ffd0984e65d1d9f2cf88cf88899247&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
ClickHouse#68493
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The wire `update` and `delete` reject a per-spec `hint`, as they reject
`collation`, instead of running without it.
- A field name of a document inserted over the wire protocol must not be empty,
start with `$` or contain a dot, as in the dialect insert. The dialect insert
rejects a dot too: `{"a.b": 1}` and `{"a": {"b": 1}}` would both map onto the
column `a.b`.
- `$size`, in a filter and in an aggregation expression, takes the type of the
value in each row for a `Dynamic` field (`makeIsRuntimeArray`), and its size
from the JSON text of the value (`makeRuntimeArraySize`), which never throws,
also with `short_circuit_function_evaluation = 'disable'`.
- The documentation states that `$unwind` requires a field of an array type.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Pushed
Tested locally: all Mongo stateless tests, the new |
…, `BFloat16`, `$toLong` of null
- The column check of a `$unionWith` of two collections reads the columns of an
unqualified collection from the temporary table of the session when there is
one of that name, as the query itself does: `system.columns` lists temporary
tables under the empty database, so the check compared two empty lists and
let a union of `a(x, y)` and `b(y, x)` relabel the fields.
- `parseData` rejects a field name that contains a zero byte. The translation
passes names on as C strings, so `{"x\u0000ignored": 1}` filtered, sorted,
updated or deleted by `x`.
- A wire insert of an integer into a `BFloat16` column, or an element of an
`Array(BFloat16)`, that the type does not hold exactly is rejected, as it is
for `Float32` and `Float64`, instead of being stored as a neighbouring value.
- `$toLong` of a `null` literal is `null`, and its range check skips a `NULL`
value, so it does not throw with short-circuit evaluation disabled.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: - `src/Interpreters/DDLTask.cpp`: took the restructured code of `DDLLogEntry::setSettingsIfRequired` from master and kept `dialect` in the list of initiator-only settings. - `docs/concepts/navigation.json`, `docs/concepts/features/interfaces/mongo.mdx`: the `interfaces` directory was reorganized into `connect-to-clickhouse`; moved the page to `protocols/compatibility/mongo.mdx` next to the MySQL and PostgreSQL pages. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The `arm_tidy` builds fail with `modernize-use-nodiscard`, which is enabled on master now, in the headers and sources under `src/Core/Mongo` and `src/Parsers/Mongo`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=68493&sha=91c6295705c02b8d27e72eac37ae11c437101700&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 ClickHouse#68493 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…` of a BSON regex, `maxTimeMS` of DDL
- The identifiers the translation generates (`__mongo_variable_x` for `$$x`,
`__mongo_value_1`, `__mongo_element` and so on) could still be captured by a
document field of the same name. The prefix `__mongo_` is reserved now: a
query that names such a field, and an insert of a document that has one, is
rejected, so the generated names are disjoint from every field a query
refers to.
- `$size` takes only a number or the Extended JSON wrapper of one. A boolean
or a string operand was compared with the length, so
`deleteMany({"a": {"$size": true}})` deleted the arrays of one element.
- The `$options` next to a `$regex` that holds a BSON regular expression were
dropped, so a negated case-insensitive match deleted the documents it should
have kept. They are applied now, for both Extended JSON forms of the regular
expression; options in both places are an error, as in MongoDB.
- `drop`, `dropDatabase` and `createIndexes` reject a non-zero `maxTimeMS`,
as `create` does, because their DDL is not bounded by `max_execution_time`.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged
Three older threads stay open because they need a human decision, as explained in each: the overflow of an arithmetic result in |
The `settings_changes_history` style check requires a new setting to be recorded under the current version. Co-Authored-By: Claude Fable 5.2 <[email protected]>
MongoDB unwinds a field that is not an array into itself: the document is kept once with the field unchanged and a null `includeArrayIndex`, and it is dropped when the field is null unless `preserveNullAndEmptyArrays` is set. The Mongo dialect lowered every path through `ARRAY JOIN`, so `[{"$unwind": "$name"}]` on a `String` column failed with `ARRAY JOIN of not array nor map`.
The translation does not know the type of the column, so the array to join is chosen by a constant condition on `toTypeName` of the field. A plain `if` would need a common type of an array and its element, so the choice is written as nested `if` functions whose unselected branches name a column that does not exist: the analyzer replaces an `if` of a constant condition with the selected branch when the other one cannot be analyzed, so the type of the field is kept as it is.
Both forms of `$unwind` now compute the array and its indexes below the `ARRAY JOIN` under names of their own. A `Dynamic` or a `Variant` column, which can hold an array in one row and another value in the next, is still rejected.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged
Two threads stay open because they need a human decision, as explained in each:
While these two threads are unresolved, the review-threads gate in |
| auto offset = makeASTFunction( | ||
| "if", positive, makeASTFunction("plus", position->clone(), makeLiteral(Field(UInt64(1)))), position->clone()); | ||
| return makeASTFunction("arraySlice", arguments[0], offset, arguments[2]); |
There was a problem hiding this comment.
[Blocker] Clamp an oversized negative $slice position before applying the count. On a nonempty collection, db.t.aggregate([{"$project":{"s":{"$slice":[[1,2,3],-15,2]}}}]) becomes arraySlice([1,2,3], -15, 2) and returns []. MongoDB requires [1,2] for this exact input: a negative position beyond the array starts at its beginning. ClickHouse instead subtracts the out-of-range distance from the requested length (src/Functions/GatherUtils/Sources.h:134-139). Clamp against the array length, binding the input once to keep AST growth bounded, and add oversized and ordinary negative-position regressions for the shared dialect/wire lowering.
| auto matched = makeASTFunction("match", input, pattern); | ||
| auto whole_match = makeASTFunction("regexpExtract", input, pattern, makeLiteral(Field(UInt64(0)))); | ||
|
|
||
| result.push_back({name + ".match", makeASTFunction("if", matched, whole_match, makeNull())}); |
There was a problem hiding this comment.
[Blocker] Preserve the nullness of the whole $regexFind result. On a nonempty collection, projecting {"r":{"$regexFind":{"input":"b","regex":"a"}}} emits three null leaf columns here. The wire encoder's appendFieldTree unconditionally wraps those leaves into {"r":{"match":null,"idx":null,"captures":null}} (src/Core/Mongo/Handler.cpp:648-652), whereas MongoDB requires {"r":null} when no match exists. Clients therefore receive a non-null object for an unsuccessful search. Carry parent nullness through the result representation and add a wire regression for a missing match. This concerns an unsuccessful match, separately from the existing thread about capture groups within a successful match.
Adds two ways to run MongoDB queries against ClickHouse:
mongo_port), so MongoDB drivers and tools such aspymongoandmongoshcan connect to ClickHouse as if it were a MongoDB server;SET dialect = 'mongo'), so MongoDB shell syntax can be sent over the usual ClickHouse interfaces.A Mongo database maps onto a ClickHouse database, a collection onto a table, a document onto a row, and a nested field onto an
a.bcolumn. A collection created by the firstinsertgets one column per field of the first inserted document. The supported commands areinsert,find,count,update,delete,create,drop,createIndexes,listDatabases,listCollections,isMasterandsaslStart; only thePLAINauthentication mechanism is supported, because it is the only one that provides the cleartext password ClickHouse needs.Both are experimental and cover a subset of MongoDB. They are meant for pointing an existing MongoDB application at ClickHouse without rewriting its queries, not as a MongoDB replacement. The limitations are listed in
docs/en/interfaces/mongo.md.Task: #58394
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a MongoDB-compatible wire protocol endpoint (the
mongo_portserver setting) and a MongoDB query dialect (SET dialect = 'mongo') for basic collection operations.Workflow [PR]
Sync PR [sync-upstream/pr/68493]