Repository navigation
Conversation
`writeFieldJSON` wrote a `Float64` field with `writeFloatText`, which prints
values such as `9.99e19` in positional notation (`99900000000000000000`). The
JSON reader takes a number without `.` or an exponent for an integer and
fails when it does not fit 64 bits, so `formatQueryFromJSON` could not read
the output of `parseQueryToJSON('SELECT 9.99e19')`:
Code: 36. DB::Exception: Failed to parse JSON for AST deserialization:
Syntax error: Not a valid unsigned integer: '99900000000000000000'
Append `.0` when the shortest representation has no `.`, `e` or `E`, so the
token is always lexed as a floating point number. Covered by the test added
with the `DescribeQuery` JSON support (05248).
Found while converting the functional-test statements into a seed corpus for
`json_ast_sql_parser_fuzzer` (finding 25 of the JSON AST fuzzing campaign).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
`parseQueryToJSON` rejected `ASTDescribeQuery` (`DESCRIBE`/`DESC`) and `ASTObjectTypeArgument`/`ASTObjectTypedPathArgument` (the arguments of the `JSON(...)` type in column definitions and `CAST`). Measured over the statements of the functional tests, these were the two largest classes of unsupported syntax (523 and 286 statements), so neither the parser fuzzer nor the execution fuzzer could ever generate them. - `DescribeQuery`: `temporary`, child `table_expression`, output options. - `ObjectTypedPathArgument`: `path` and child `data_type`. - `ObjectTypeArgument`: exactly one of `path_with_type`, `skip_path`, `skip_path_regexp`, `parameter`; anything else is `BAD_ARGUMENTS`. - Registered in the AST factory and in `json_ast.proto` (node types 94-96, keys 403-407) so the structure-aware fuzzers generate them. Test 05248 round-trips `DESCRIBE` variants, `JSON(...)` type arguments and the large `Float64` literals from the previous commit. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`ParserDataType` accepts a tuple type that names only some of its elements,
such as `Tuple(CPU, double, Memory double)` (`DataTypeFactory` rejects the
mix later, at execution). `ASTTupleDataType::writeJSON` wrote the unnamed
elements as empty strings and `readJSON` threw for any empty name, so
`formatQueryFromJSON` refused the output of `parseQueryToJSON`:
Code: 36. DB::Exception: ASTTupleDataType element name must not be empty
during AST JSON deserialization
Treat an empty entry as an unnamed element, like the formatter does; the
"one name per element" check stays.
Found by the JSON round-trip stage of `json_ast_sql_parser_fuzzer` (finding 26
of the JSON AST fuzzing campaign).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
`BACKUP TABLE d.t AS t` (and `RESTORE ... AS t`) stores the target as `new_table_name = "t"`, `new_database_name = ""`; the current database is substituted at execution. `ASTBackupQuery::writeJSON` omitted the empty new database name and `readJSON` defaults a missing one to the old database, so `formatQueryFromJSON(parseQueryToJSON(...))` dropped the `AS` clause. For `RESTORE` that changes the destination table. Write a new name whenever it differs from the old one, including the empty database. Found by the JSON round-trip stage of `json_ast_sql_parser_fuzzer` (finding 27 of the JSON AST fuzzing campaign). Co-Authored-By: Claude Fable 5.1 <[email protected]>
`ParserTTLElement` parses the keys of `TTL expr GROUP BY` with
`ParserExpressionList`, which accepts an empty list, and `MergeTree` accepts
such a table. `ASTTTLElement::readJSON` rejected an empty `group_by_key` in
`GROUP_BY` mode as a shape the parser could not produce, so
`formatQueryFromJSON` refused the output of `parseQueryToJSON` for
`ALTER TABLE t MODIFY TTL d GROUP BY`:
Code: 36. DB::Exception: TTL GROUP BY requires a non-empty 'group_by_key'
during AST JSON deserialization
Accept the empty list; keys or assignments on the other TTL modes are still
rejected.
Found by the JSON round-trip stage of `json_ast_sql_parser_fuzzer` (finding 28
of the JSON AST fuzzing campaign).
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [12c788d] Summary: ❌
AI ReviewSummaryThe PR fixes JSON AST round trips for floating-point literals, tuples, backup renames, and TTL clauses, and adds support for Findings
Tests
Final VerdictStatus: |
Sibling PR ClickHouse#121585 → group 11 already had 05248-05251; the finding 30 fix (JIT number to Decimal) in PR-in-preparation claims 05252 (05252_jit_number_to_decimal_overflow). Move the sweep further out of the way. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…ding 28 fix) The finding-28 fix accepts an empty `group_by_key` on a `GROUP_BY` TTL, matching `MergeTree` which accepts `TTL d GROUP BY` with no keys (aggregates the whole part). Drop that case; keep the reverse case (adding `group_by_key` to a `DELETE` TTL is still rejected). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ASTDescribeQuery.cpp.o |
new | 303.42 KiB | +303.42 KiB |
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ASTObjectTypeArgument.cpp.o |
67.74 KiB | 321.06 KiB | +253.32 KiB (+373.94%) |
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ParserDescribeTableQuery.cpp.o |
94.61 KiB | 62.12 KiB | -32.49 KiB (-34.34%) |
src/Parsers/CMakeFiles/clickhouse_parsers.dir/ASTJSONHelpers.cpp.o |
37.84 KiB | 68.13 KiB | +30.29 KiB (+80.06%) |
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
24 translation units recompiled, 87 s compile time in total, 23 of them have a recent master baseline.
…alization `ParserTTLElement` accepts `WHERE` only after `DELETE`, and `TTLDescription` applies it only for `DELETE`, but `ASTTTLElement::readJSON` restored `where_expr` for every mode. A `clickhouse_json` `CREATE TABLE ... TTL d TO DISK 'default'` carrying a `where_expr` was therefore accepted, the `WHERE` was ignored, and `formatImpl` stored `TTL d TO DISK 'default' WHERE x`, which fails to parse at the next start (`Code: 62`), so the database does not load. Same for `RECOMPRESS` and `GROUP BY`; `formatQueryFromJSON` returned the same unparsable SQL. Reject `where_expr` unless the mode is `DELETE`, like the existing per-mode checks for the codec, destination and `GROUP BY` fields in the same function. The check sits at the read site so it does not textually overlap ClickHouse#108069 (which adds the same check for its new `CLEAR INDEX` mode) or ClickHouse#121585. Requested in ClickHouse#108069 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…DESCRIBE TEMPORARY
Three parser-impossible shapes that the new JSON AST round-trip readers
accepted:
* `ASTObjectTypedPathArgument` 'data_type' used `IAST::as<ASTDataType>()`,
which matches `typeid` exactly and rejects the `ParserDataType` subclasses
`ASTTupleDataType` and `ASTEnumDataType`. Round-tripping
`CREATE TABLE t (j JSON(a Tuple(UInt64, String))) ENGINE = Memory`
(and the `Enum8` counterpart) threw `BAD_ARGUMENTS` on read even though
write produced a valid payload. Use `dynamic_cast<const ASTDataType *>`
to accept the whole hierarchy, mirroring `ASTColumnDeclaration::readJSON`.
* `ASTDescribeQuery` accepted `temporary = true` alongside any
`table_expression`, but `ParserDescribeTableQuery` sets the flag only in
the `DESCRIBE TEMPORARY TABLE <name>` branch after confirming the table
expression is a bare name. A payload setting `temporary` with a subquery
or table-function `table_expression` formats as
`DESCRIBE TEMPORARY TABLE (SELECT ...)` / `... TABLE numbers(1)`, which
the SQL parser cannot read back. Require `database_and_table_name` when
`temporary` is true.
* `ASTObjectTypeArgument` accepted any `ASTLiteral` for `skip_path_regexp`
and any `ASTFunction` for `parameter`. `ObjectArgumentParser` parses the
regexp with `ParserStringLiteral` and builds the parameter with
`makeASTOperator("equals", identifier, number)`. A numeric
`skip_path_regexp` would format as `SKIP REGEXP 42`, and an arbitrary
`parameter` function would format as `JSON(<garbage>)`. Validate those
shapes at the JSON boundary: a `String`-typed `ASTLiteral` for the regexp
and an `equals` operator with exactly `(ASTIdentifier, numeric ASTLiteral)`
arguments for the parameter.
Add stateless regression rows to the test file this PR owns
(04350_ast_json_parser_impossible_field_combinations): two valid typed-path
round-trips (`Tuple(UInt64, String)` and `Enum8('a'=1)`), one malformed
`temporary=true + subquery` payload, and two malformed `ObjectTypeArgument`
payloads (numeric `skip_path_regexp` and non-`equals` `parameter`).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Review follow-up landed as Major 1 — typed JSON paths rejected Major 2 — Major 3 —
Regression cases in
|
| { | ||
| JSONObjectWriter w(out, "ObjectTypedPathArgument"); | ||
| w.writeString("path", path); | ||
| w.writeChild("data_type", type); |
There was a problem hiding this comment.
[P2] Preserve the SHARED modifier on typed JSON paths
When merged with current master, ASTObjectTypedPathArgument also carries shared, but this writer emits only path and data_type and the reader leaves shared = false. With this PR's Fast test binary, SELECT formatQueryFromJSON(parseQueryToJSON('CREATE TABLE t (j JSON(SHARED a UInt64)) ENGINE = MergeTree ORDER BY tuple()')) returns a declaration containing JSON(a UInt64). Nested typed paths lose the modifier too.
This silently changes the requested storage layout: The createObject factory in DataTypeObject.cpp uses this flag to select typed shared storage, so executing the JSON representation creates a different schema and uses separate files for every affected path. Please serialize and restore shared (defaulting to false for existing payloads), and add a round-trip regression for direct and nested SHARED paths against current master.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Round-trip fixes for
parseQueryToJSON/formatQueryFromJSON(clickhouse_jsondialect): largeFloat64literals stay readable,Tuple(...)types with partially named elements deserialize,BACKUP/RESTORE ... AS trename into the current database survives the round trip, andTTL expr GROUP BYwithout grouping keys is accepted on read. Also extends the JSON AST reader to acceptDESCRIBEand theJSON(...)type arguments.Documentation entry for user-facing changes
No documentation change needed.
Detailed description / Documentation
Five commits, each one JSON AST reader/writer pair, from the JSON-AST fuzzer's new round-trip stage. Each has a matching
05248-05251stateless test.Float64literal (parseQueryToJSON writes a large Float64 literal that formatQueryFromJSON cannot read back (integer overflow in Poco JSON parser) #121580) —writeFieldJSONprinted values like9.99e19in positional notation (99900000000000000000); the Poco JSON parser treats a token without./eas an integer and fails for values above 2^64. Fix appends.0when the shortest float text has none of./e/E.1e300,1.5,1e-7unchanged. Test05248.DESCRIBEandJSON(...)type arguments — coverage extension bundled with the previous commit (the two largest classes of unsupported syntax in the functional-test corpus: 523 and 286 statements). AddsASTDescribeQuery::readJSON/writeJSON,ASTObjectTypeArgument::readJSON/writeJSON,ASTObjectTypedPathArgumentsupport, registered in the AST factory. Test05248is extended.Tuple(...)(formatQueryFromJSON rejects parseQueryToJSON output for a partially named Tuple(...) type (empty element name) #121581) —ParserDataTypeacceptsTuple(CPU, double, Memory double)withelement_names = ["", "", "Memory"](DataTypeFactoryrejects the mix later, at execution).ASTTupleDataType::writeJSONwrote empty names;readJSONrefused them. Fix accepts empty names as unnamed elements, matching the writer and the formatter. Test05249.BACKUP/RESTORE ... AS tinto the current database (BACKUP/RESTORE ... TABLE db.t AS t loses the rename through parseQueryToJSON / formatQueryFromJSON (RESTORE target silently changes database) #121582) —ASTBackupQuery::writeJSONwrotenew_database_nameonly when non-empty;readJSONdefaulted a missingnew_database_nametodatabase_name. SoRESTORE TABLE d.t AS t FROM ...(restore into the current database) silently becameRESTORE TABLE d.t FROM ...(restore intod). Fix writesnew_table_name/new_database_namewhenever they differ fromtable_name/database_name. Test05250. Medium-severity: only surface is the JSON AST dialect but the semantics change.TTL expr GROUP BYwithout grouping keys (formatQueryFromJSON rejects parseQueryToJSON output for TTL expr GROUP BY without grouping keys #121583) —ParserTTLElementandMergeTreeaccept an empty key list (aggregates the whole part);ASTTTLElement::readJSONrejected it. Fix accepts the empty key list inGROUP_BYmode; keys or assignments on the other modes are still rejected. Test05251.Note: the fuzzer's own
json_ast_sql_parser_fuzzer/json_ast.protochange from the DESCRIBE-support commit stays with the fuzzer harness PR (#121057) and is not part of this PR.Closes: #121580
Closes: #121581
Closes: #121582
Closes: #121583
cc @groeneai — fuzz-lab find (JSON AST fuzzer)
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121585]