mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
a85cf758b0
Create a table function `fuzzJSON` An example query: ``` CREATE NAMED COLLECTION json_fuzzer AS json_str={}; SELECT * FROM fuzzJSON(json_fuzzer, json_str = '{"students" : ["Alice", "Bob"]}', random_seed = 666, max_output_length = 128, probability = 0.9) LIMIT 3 Query id: 7f802052-efb0-41b4-87fa-03b7dd290e9d ┌─json──────────────────────────────────────────────────────────────────────────────────┐ │ {"ade0yX":[9200406572736542991, true, "sm"]} │ │ {"students":["Alice", "eSN3WO#a6NYTBe0$#OWwyIQ"], "cVoP2BuQugQ":17384271928263249403} │ │ {"students":["Alice", "Bob", "T+-k4+PJGkL%XRRaF2BoeN@&A"]} │ └───────────────────────────────────────────────────────────────────────────────────────┘ ``` Next step: * Generate invalid string Fixes #35962 add Object('json') use named collection
87 lines
2.9 KiB
Markdown
87 lines
2.9 KiB
Markdown
---
|
|
slug: /en/sql-reference/table-functions/fuzzJSON
|
|
sidebar_position: 75
|
|
sidebar_label: fuzzJSON
|
|
---
|
|
|
|
# fuzzJSON
|
|
|
|
Perturbs a JSON string with random variations.
|
|
|
|
``` sql
|
|
fuzzJSON({ named_collection [option=value [,..]] | json_str[, random_seed] })
|
|
```
|
|
|
|
**Arguments**
|
|
|
|
- `named_collection`- A [NAMED COLLECTION](/docs/en/sql-reference/statements/create/named-collection.md).
|
|
- `option=value` - Named collection optional parameters and their values.
|
|
- `json_str` (String) - The source string representing structured data in JSON format.
|
|
- `random_seed` (UInt64) - Manual random seed for producing stable results.
|
|
- `reuse_output` (boolean) - Reuse the output from a fuzzing process as input for the next fuzzer.
|
|
- `max_output_length` (UInt64) - Maximum allowable length of the generated or perturbed JSON string.
|
|
- `probability` (Float64) - The probability to fuzz a JSON field (a key-value pair). Must be within [0, 1] range.
|
|
- `max_nesting_level` (UInt64) - The maximum allowed depth of nested structures within the JSON data.
|
|
- `max_array_size` (UInt64) - The maximum allowed size of a JSON array.
|
|
- `max_object_size` (UInt64) - The maximum allowed number of fields on a single level of a JSON object.
|
|
- `max_string_value_length` (UInt64) - The maximum length of a String value.
|
|
- `min_key_length` (UInt64) - The minimum key length. Should be at least 1.
|
|
- `max_key_length` (UInt64) - The maximum key length. Should be greater or equal than the `min_key_length`, if specified.
|
|
|
|
**Returned Value**
|
|
|
|
A table object with a a single column containing perturbed JSON strings.
|
|
|
|
## Usage Example
|
|
|
|
``` sql
|
|
CREATE NAMED COLLECTION json_fuzzer AS json_str='{}';
|
|
SELECT * FROM fuzzJSON(json_fuzzer) LIMIT 3;
|
|
```
|
|
|
|
``` text
|
|
{"52Xz2Zd4vKNcuP2":true}
|
|
{"UPbOhOQAdPKIg91":3405264103600403024}
|
|
{"X0QUWu8yT":[]}
|
|
```
|
|
|
|
``` sql
|
|
SELECT * FROM fuzzJSON(json_fuzzer, json_str='{"name" : "value"}', random_seed=1234) LIMIT 3;
|
|
```
|
|
|
|
``` text
|
|
{"key":"value", "mxPG0h1R5":"L-YQLv@9hcZbOIGrAn10%GA"}
|
|
{"BRE3":true}
|
|
{"key":"value", "SWzJdEJZ04nrpSfy":[{"3Q23y":[]}]}
|
|
```
|
|
|
|
``` sql
|
|
SELECT * FROM fuzzJSON(json_fuzzer, json_str='{"students" : ["Alice", "Bob"]}', reuse_output=true) LIMIT 3;
|
|
```
|
|
|
|
``` text
|
|
{"students":["Alice", "Bob"], "nwALnRMc4pyKD9Krv":[]}
|
|
{"students":["1rNY5ZNs0wU&82t_P", "Bob"], "wLNRGzwDiMKdw":[{}]}
|
|
{"xeEk":["1rNY5ZNs0wU&82t_P", "Bob"], "wLNRGzwDiMKdw":[{}, {}]}
|
|
```
|
|
|
|
``` sql
|
|
SELECT * FROM fuzzJSON(json_fuzzer, json_str='{"students" : ["Alice", "Bob"]}', max_output_length=512) LIMIT 3;
|
|
```
|
|
|
|
``` text
|
|
{"students":["Alice", "Bob"], "BREhhXj5":true}
|
|
{"NyEsSWzJdeJZ04s":["Alice", 5737924650575683711, 5346334167565345826], "BjVO2X9L":true}
|
|
{"NyEsSWzJdeJZ04s":["Alice", 5737924650575683711, 5346334167565345826], "BjVO2X9L":true, "k1SXzbSIz":[{}]}
|
|
```
|
|
|
|
``` sql
|
|
SELECT * FROM fuzzJSON('{"id":1}', 1234) LIMIT 3;
|
|
```
|
|
|
|
``` text
|
|
{"id":1, "mxPG0h1R5":"L-YQLv@9hcZbOIGrAn10%GA"}
|
|
{"BRjE":16137826149911306846}
|
|
{"XjKE":15076727133550123563}
|
|
```
|