Repository navigation
Conversation
… generateRandom `generateRandom()` and the `GenerateRandom` storage engine previously threw `NOT_IMPLEMENTED` for the `JSON`, `Dynamic`, `Variant`, `BFloat16`, `Time`, and `Time64` types. This commit adds dispatch cases for all of them in `fillColumnWithRandomData` and `estimateValueSize`. JSON (`TypeIndex::Object`): typed paths are filled recursively using the existing dispatch; a configurable number of dynamic paths (controlled by the new `generate_random_max_json_dynamic_keys` setting, default 5) are added as `Dynamic` sub-columns; shared data is left empty. `Dynamic` (`TypeIndex::Dynamic`): values are drawn from a pool of four scalar types (UInt64, Int64, Float64, String); ~6 % of rows are null, matching the existing Nullable probability. `Variant` (`TypeIndex::Variant`): for each row a random variant type is chosen and a single value of that type is inserted via `ColumnVariant::insertIntoVariantFrom`. `BFloat16` / `Time` / `Time64`: straightforward fixed-size fills using `fillBufferWithRandomNumbers`, analogous to the existing UInt16 / Int32 / DateTime64 cases. New setting `generate_random_max_json_dynamic_keys` (UInt64, default 5) limits how many randomly-generated dynamic paths each JSON object column contains, and is exposed via the `SETTINGS` clause in SELECT or CREATE. Drive-by fix: `TableFunctionGenerateRandom.cpp` was passing the label `"max_string_length"` to `checkAndGetLiteralArgument` when parsing the `max_array_length` positional argument; corrected to `"max_array_length"`. Closes: ClickHouse#92360 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Thanks for picking this up. I reviewed it against the design notes on #92360 and the ClickHouse review checklist. The type dispatch is sound and the API usage checks out: Blockers (CI will fail):
Correctness / quality:
Note: BFloat16/Time/Time64 correctly need no The tests all use |
- Register `generate_random_max_json_dynamic_keys` in `SettingsChangesHistory.cpp` under the 26.6 block so the `02995_new_settings_history` test passes. - Add NULL discriminator to `Variant` fill: one out of `variants.size() + 1` outcomes now inserts `NULL_DISCRIMINATOR`, exercising the untyped-null state. - Clamp `Time` to `[-3 599 999, 3 599 999]` seconds and `Time64` to `[-3 599 999 * 10^scale, 3 599 999 * 10^scale]` ticks so that random raw `Int32`/`Int64` values no longer saturate to the boundary on text output. - Prefix generated dynamic-path keys as `_rnd_0`, `_rnd_1`, … to avoid collision with user-declared typed paths such as `JSON(k0 UInt32)`. - Propagate `max_json_dynamic_keys` through `estimateValueSize` (new default parameter) and use it for the `Object` case instead of the hardcoded `5`. Also read the setting from `context` at the `read()` call site so the block-size estimate tracks the actual setting value. - Extend the stateless test with `FORMAT Null` serialization queries (catches text-serialization exceptions like the former `Time` saturation) and `toTypeName` checks for `BFloat16`, `Time`, `Time64(3)`, `Dynamic`, and `Variant(UInt64, String)`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ndom-json-dynamic-variant
…eate signature Master commit 1369f4c added the `max_dynamic_paths_upper_bound_` parameter to `ColumnObject::create`, between `max_dynamic_paths_` and `global_max_dynamic_paths_`. After merging master into this branch the `TypeIndex::Object` case in `fillColumnWithRandomData` no longer compiled. Pass the type's `getMaxDynamicPaths` for all three path limits, which is how the three-argument `ColumnObject` constructor initializes them. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Hi @apst41, thanks again for the PR and for addressing the first review round! I've merged the latest The one thing only you can fix is the CLA. Your commits are authored as Option A (simplest, no git changes):
Option B (if you can't link that address): rewrite your two commits with an email that is already linked to your GitHub account, then sign the CLA and trigger the recheck as above. Before you do that, please pull the branch first: it now has two extra commits on top of yours (the merge from Thanks a lot, and let me know if anything is unclear! |
|
Workflow [PR], commit [a0d653c] Summary: ✅
AI ReviewSummaryThis PR extends Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit a0d653c.
Changed lines: Changed C/C++ lines covered: 656/686 (95.63%) · Uncovered code |
392ecf9 to
f2cea2e
Compare
|
@naushniki Thanks for the Merging the latest master code |
…andom scan in test Move the `generate_random_max_json_dynamic_keys` entry from the `26.6` to the `26.10` block in `SettingsChangesHistory.cpp`, as required by the `settings_changes_history` style check for the current version. In `04357_generate_random_json_dynamic_variant.sql`, `SELECT count() > 0 FROM generateRandom(...) LIMIT N` applies `LIMIT` to the 1-row aggregate result rather than the source scan, so `generateRandom` kept generating rows until it hit `max_rows_to_read` (20M) and the Fast test failed with `TOO_MANY_ROWS`. Wrap each `generateRandom(...)` call (and the `GenerateRandom`-engine table reads) in a subquery with `LIMIT` so the scan itself is bounded.
…ndom-json-dynamic-variant # Conflicts: # src/Core/SettingsChangesHistory.cpp
827bac2 to
02213bd
Compare
`Nullable(Dynamic)` is rejected by the type system itself
(`DataTypeNullable` throws `ILLEGAL_TYPE_OF_ARGUMENT`, since `Dynamic`
already represents `NULL` internally), so `generateRandom('x
Nullable(Dynamic)', ...)` can never succeed. This caused the Fast
test to fail with `Nested type Dynamic cannot be inside Nullable
type`. Drop the invalid case rather than testing for an error that
belongs to the type system, not to `generateRandom`.
CREATE TABLE ... ENGINE = GenerateRandom with a JSON or Dynamic column failed with: Code: 44. DB::Exception: Cannot create table with column of type Dynamic or JSON, because storage GenerateRandom doesn't support columns with dynamic structure. (ILLEGAL_COLUMN) `checkForUnsupportedColumns` in InterpreterCreateQuery.cpp rejects such columns unless the storage overrides `supportsColumnsWithDynamicStructure()`. `StorageGenerateRandom` generates JSON/Dynamic/Variant data just fine (the underlying `fillColumnWithRandomData` already supports these types), it simply never opted in to the check. Add the override, matching `StorageMemory` and `StorageNull`.
…ndom-json-dynamic-variant # Conflicts: # src/Core/SettingsChangesHistory.cpp
DataTypeVariant's constructor sorts nested types by their full names and squashes identical types (src/DataTypes/DataTypeVariant.cpp), so Variant(UInt64, String) is canonicalized to Variant(String, UInt64). The test asserted the declared order rather than the canonical one, causing the Fast test to fail with a reference mismatch.
fillColumnWithRandomData caps the real number of random dynamic paths generated for an Object/JSON column at min(max_json_dynamic_keys, object_type.getMaxDynamicPaths()), but estimateValueSize still charged max_json_dynamic_keys unconditionally. On a low-cap schema such as JSON(max_dynamic_paths=0) or JSON(max_dynamic_paths=1), raising generate_random_max_json_dynamic_keys made read() shrink max_block_size based on rows the generator can never produce, degenerating throughput toward 1-row blocks. Apply the same cap the generator uses. Flagged by CI code review on ClickHouse#107966.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+352.71 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units9 translation units recompiled, 19 s compile time in total, 8 of them have a recent master baseline. |
New `SETTINGS` clause on the `generateRandom` table function and the `GenerateRandom` table engine: - `max_json_depth`: max nesting depth, default 3 - `max_json_keys_per_object`: max keys per object, default 8 - `null_ratio`: a probability factor (0.0 to 1.0) defining how often fields are omitted or null, default 0.0625, the previous fixed 1/16 - strings size: the existing argument `max_string_length` - array size: the existing argument `max_array_length` Each `JSON` column now gets a schema derived from the seed: readable key names, nested objects, sparse keys, typed paths, `SKIP` and `SKIP REGEXP` rules, arrays of objects, mixed arrays and type drift. `Dynamic` and `Variant` columns are built in bulk from a type schema drawn per query. Values of the previously supported types are unchanged for a given seed. The session setting `generate_random_max_json_dynamic_keys` and the test 04357 are removed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…bers `cppcoreguidelines-pro-type-member-init` reported `JSONSchema::Leaf::absent_threshold` and `GenerateRandomContext::schema_seed` in `StorageGenerateRandom.cpp` as never initialized by a constructor, which fails the tidy build because the repository treats all warnings as errors. Both fields were always assigned by every construction site before use, so adding `= 0` default member initializers silences the check without changing the generated data for any seed. CI: https://github.com/ClickHouse/ClickHouse/actions/runs/35714934163/job/106731303212 Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=107966&sha=50e28174af3a4a2e5cdde0cb564fb697e92289fc&name_0=PR PR: ClickHouse#107966 Co-Authored-By: Claude Fable 5.1 <[email protected]>
In the CI flaky check (ASan+UBSan, S3 storage, 8 parallel workers, random settings) `05238_generate_random_json` took 75-259 s per run against the 180 s limit. The structural checks over seed 45 now scan 2000 rows instead of 10000, the brace-depth scans 100 rows instead of 1000 and the comparison of `distinctJSONPaths` across streams 10000 rows instead of 100000; the `MergeTree` round trip, the tables with the tightest `max_dynamic_types` and `max_dynamic_paths` and the `GenerateRandom` engine table moved to the new `05239_generate_random_json_merge_tree`, with the round trip inserting 5000 rows instead of 100000. The server-side time of the statements on a Debug build went from 675 ms for the one test to 151 ms and 136 ms for the two. PR: ClickHouse#107966 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…riant The schema of a generated `Dynamic` column - one to four types drawn from the seed - no longer depends on `max_types`. The limit only decides storage: the first `min(max_types, width)` types get a variant of their own, the rest are encoded into `SharedVariant`, as `ColumnDynamic` does once its limit is reached. `JSON` keys drift between two types for every `max_dynamic_types`, the second type spilling into the shared variant of the path column. Values for the default limit, `Variant` columns and all other types are unchanged for a given seed. Tests 05237 and 05238 check the dedicated and shared types of `Dynamic(max_types=1)` and `JSON(max_dynamic_types=1)` and a `MergeTree` round trip of the shared values. Addresses: ClickHouse#107966 (comment) PR: ClickHouse#107966 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Closes: #92360
Related: #94832
generateRandom()table function and theGenerateRandomstorage engine threwNOT_IMPLEMENTEDfor theJSON,Dynamic,Variant,BFloat16,Time, andTime64types. This PR adds full support for all of them.What changed:
JSON(TypeIndex::Object): typed paths are filled recursively via the existing dispatch;a configurable number of random dynamic paths (controlled by the newEachgenerate_random_max_json_dynamic_keyssetting, default5) are generated; shared data is left empty.JSONcolumn gets a schema derived from the seed: readable key names from a fixed vocabulary, nested objects up tomax_json_depth, at mostmax_json_keys_per_objectkeys per level, sparse keys,SKIPandSKIP REGEXPrules, arrays of objects, mixed arrays and per-key type drift. Paths beyondmax_dynamic_pathsgo to shared data. The same seed gives the same documents.Dynamic(TypeIndex::Dynamic): ~~values are drawn from a pool of four scalar types (UInt64,Int64,Float64,String); ~6 % of rows areNULL.~~ A type schema is drawn per query from a pool that imitates what the JSON parser infers, and the column is built in bulk. TheNULLshare isnull_ratio.max_dynamic_typesis honoured, including0.Variant(TypeIndex::Variant):for each row a random variant type is chosen and one value is inserted; one out ofDiscriminators are drawn in bulk and each variant is filled with the existing generator of its type. Thevariants.size() + 1outcomes inserts the untyped-null (NULL_DISCRIMINATOR) state.NULLshare isnull_ratio.BFloat16/Time/Time64:BFloat16fills raw bits likeUInt16.TimeandTime64generate values clamped to[-999:59:59, 999:59:59](and its10^scaleequivalent forTime64) so that random raw integers no longer saturate to the display boundary. (Edit: theTimecases now also honour thefuzzymode used for the other date and time types.)estimateValueSizeextended forDynamic,Variant, andObjectand now accepts and propagatesand now uses the per-column schema, so that block-size estimation formax_json_dynamic_keysso that block-size estimation tracks the actual setting value.preferred_block_size_bytesmatches the data actually generated.New settinggenerate_random_max_json_dynamic_keys(UInt64, default5): limits how many randomly-generated dynamic paths eachJSONobject column contains. Registered inSettingsChangesHistory.cppunder 26.10. Exposed viaSETTINGSinSELECT(query/session level) only —GenerateRandomhas no storage-settings framework, so aSETTINGSclause onCREATE TABLE ... ENGINE = GenerateRandomis not persisted in table metadata; reads always use whichever setting is active at query time.New
SETTINGSclause on the table function and the engine, persisted in the table metadata forENGINE = GenerateRandom:max_json_depth: max nesting depth, default3max_json_keys_per_object: max keys per object, default8null_ratio: a probability factor (0.0 to 1.0) defining how often fields are omitted or null, default0.0625, the previous fixed 1/16max_string_lengthmax_array_lengthDrive-by bug fix:
TableFunctionGenerateRandom.cppwas passing the label"max_string_length"tocheckAndGetLiteralArgumentwhen parsing themax_array_lengthpositional argument; corrected to"max_array_length".Tests:
Five tests, one per area:04357_generate_random_json_dynamic_variant.sqlcovers all new type cases,ENGINE = GenerateRandomfor each type,FORMAT Nullserialization smoke tests,toTypeNamechecks, the new setting, and the label bug fix.05234_generate_random_null_ratio,05235_generate_random_settings(validation, persistence throughATTACH),05236_generate_random_time_bfloat16,05237_generate_random_variant_dynamic,05238_generate_random_json(schema properties,SKIPrules, typed paths, subcolumn reads, engine table). A performance testtests/performance/generate_random_json.xmlcoversJSON,DynamicandVariant. The output for all previously supported types is unchanged for a given seed.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
generateRandomtable function and theGenerateRandomtable engine supportJSON,Dynamic,Variant,BFloat16,TimeandTime64. GeneratedJSONdocuments have a realistic schema derived from the seed. The new settingsnull_ratio,max_json_depthandmax_json_keys_per_objectcontrol the share of nulls and absent keys, the nesting depth and the number of keys per object, for examplegenerateRandom('x JSON', 1, SETTINGS max_json_depth = 2).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/107966]
Version info
26.10.1.498-master(included in26.10and later)