Fuzz JSON table function
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
2023-11-03 03:59:45 +00:00
|
|
|
DROP TABLE IF EXISTS 02919_test_table_noarg;
|
|
|
|
CREATE TABLE 02919_test_table_noarg(str String) ENGINE = FuzzJSON('{}');
|
|
|
|
|
|
|
|
SELECT count() FROM (SELECT * FROM 02919_test_table_noarg LIMIT 100);
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_noarg;
|
|
|
|
|
|
|
|
--
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_valid_args;
|
|
|
|
CREATE TABLE 02919_test_table_valid_args(str String) ENGINE = FuzzJSON(
|
|
|
|
'{"pet":"rat"}', NULL);
|
|
|
|
|
|
|
|
SELECT count() FROM (SELECT * FROM 02919_test_table_valid_args LIMIT 100);
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_valid_args;
|
|
|
|
|
|
|
|
--
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_reuse_args;
|
|
|
|
CREATE TABLE 02919_test_table_reuse_args(str String) ENGINE = FuzzJSON(
|
|
|
|
'{
|
|
|
|
"name": "Jane Doe",
|
|
|
|
"age": 30,
|
|
|
|
"city": "New York",
|
|
|
|
"contacts": {
|
|
|
|
"email": "jane@example.com",
|
|
|
|
"phone": "+1234567890"
|
|
|
|
},
|
|
|
|
"skills": [
|
|
|
|
"JavaScript",
|
|
|
|
"Python",
|
|
|
|
{
|
|
|
|
"frameworks": ["React", "Django"]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"projects": [
|
|
|
|
{"name": "Project A", "status": "completed"},
|
|
|
|
{"name": "Project B", "status": "in-progress"}
|
|
|
|
]
|
|
|
|
}',
|
|
|
|
12345);
|
|
|
|
|
|
|
|
SELECT count() FROM (SELECT * FROM 02919_test_table_reuse_args LIMIT 100);
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_reuse_args;
|
2023-12-18 22:48:48 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_invalid_col_type;
|
|
|
|
CREATE TABLE 02919_test_table_invalid_col_type
|
|
|
|
(
|
|
|
|
str Nullable(Int64)
|
|
|
|
)
|
|
|
|
ENGINE = FuzzJSON('{"pet":"rat"}', NULL); -- { serverError BAD_ARGUMENTS }
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS 02919_test_table_invalid_col_type;
|
|
|
|
|
|
|
|
--
|
2023-12-19 02:33:44 +00:00
|
|
|
DROP TABLE IF EXISTS 02919_test_multi_col;
|
|
|
|
CREATE TABLE 02919_test_multi_col
|
|
|
|
(
|
|
|
|
str1 String,
|
|
|
|
str2 String
|
|
|
|
) ENGINE = FuzzJSON('{"pet":"rat"}', 999);
|
|
|
|
|
|
|
|
SELECT count(str1), count(str2) FROM (SELECT str1, str2 FROM 02919_test_multi_col LIMIT 100);
|
|
|
|
DROP TABLE IF EXISTS 02919_test_multi_col;
|