Skip to content

Commit

Permalink
add more values from the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeriann committed Oct 27, 2024
1 parent 3cd1bfb commit db0645b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
3 changes: 3 additions & 0 deletions config_nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"function": {
"function_aggregate": {
"function_aggregate_window_function": "10",
"function_aggregate_filter": "10",
"function_aggregate_order_by": "10",
"function_aggregate_random_expression": "10",
"function_aggregate_distinct": "10"
Expand All @@ -79,12 +80,14 @@
"window_function_partitions": "50",
"window_function_orders": "30",
"window_function_ignore_nulls": "30",
"window_function_filter_expr": "30",
"window_function_result_offset": "30",
"window_function_result_default": "30"
},
"star": {
"star_relation_name": "10",
"star_column_name_exclude_list": "20",
"star_column_name_replace_list": "20",
"star_column_name": "20",
"star_columns": {
"star_columns_true": "50",
Expand Down
3 changes: 3 additions & 0 deletions src/include/random_nums_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ enum class RandomPercentagesEnum : idx_t {
// -----------------------------------
FUNCTION_AGGREGATE_WINDOW_FUNCTION = 44,
FUNCTION_AGGREGATE_ORDER_BY = 45,
FUNCTION_AGGREGATE_FILTER = 60,
FUNCTION_AGGREGATE_DISTINCT = 46,
FUNCTION_AGGREGATE_RANDOM_EXPRESSION = 47,

Expand All @@ -107,6 +108,7 @@ enum class RandomPercentagesEnum : idx_t {
// -----------------------------------
WINDOW_FUNCTION_PARTITIONS = 48,
WINDOW_FUNCTION_ORDERS = 49,
WINDOW_FUNCTION_FILTER_EXPRESSION = 61,
WINDOW_FUNCTION_IGNORE_NULLS = 50,
WINDOW_FUNCTION_RESULT_OFFSET = 51,
WINDOW_FUNCTION_RESULT_DEFAULT = 52,
Expand All @@ -117,6 +119,7 @@ enum class RandomPercentagesEnum : idx_t {
STAR_RELATION_NAME = 53,
STAR_COLUMN_NAME = 54,
STAR_COLUMN_NAME_EXCLUDE_LIST = 55,
STAR_COLUMN_NAME_REPLACE_LIST = 62,
STAR_COLUMNS_TRUE = 56,
STAR_COLUMNS_TRUE_LAMBDA = 57,

Expand Down
3 changes: 3 additions & 0 deletions src/random_nums_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ unordered_map<string, RandomPercentagesEnum> StringToRandomPercentagesEnum = {
{ "constant_value_to_string", RandomPercentagesEnum::CONSTANT_VALUE_TO_STRING },
{ "function_aggregate_window_function", RandomPercentagesEnum::FUNCTION_AGGREGATE_WINDOW_FUNCTION },
{ "function_aggregate_order_by", RandomPercentagesEnum::FUNCTION_AGGREGATE_ORDER_BY },
{ "function_aggregate_filter", RandomPercentagesEnum::FUNCTION_AGGREGATE_FILTER },
{ "function_aggregate_random_expression", RandomPercentagesEnum::FUNCTION_AGGREGATE_RANDOM_EXPRESSION },
{ "function_aggregate_distinct", RandomPercentagesEnum::FUNCTION_AGGREGATE_DISTINCT },
{ "window_function_partitions", RandomPercentagesEnum::WINDOW_FUNCTION_PARTITIONS },
{ "window_function_filter_expr", RandomPercentagesEnum::WINDOW_FUNCTION_FILTER_EXPRESSION },
{ "window_function_orders", RandomPercentagesEnum::WINDOW_FUNCTION_ORDERS },
{ "window_function_ignore_nulls", RandomPercentagesEnum::WINDOW_FUNCTION_IGNORE_NULLS },
{ "window_function_result_offset", RandomPercentagesEnum::WINDOW_FUNCTION_RESULT_OFFSET },
{ "window_function_result_default", RandomPercentagesEnum::WINDOW_FUNCTION_RESULT_DEFAULT },
{ "star_relation_name", RandomPercentagesEnum::STAR_RELATION_NAME },
{ "star_column_name_exclude_list", RandomPercentagesEnum::STAR_COLUMN_NAME_EXCLUDE_LIST },
{ "star_column_name_replace_list", RandomPercentagesEnum::STAR_COLUMN_NAME_REPLACE_LIST },
{ "star_column_name", RandomPercentagesEnum::STAR_COLUMN_NAME },
{ "star_columns_true", RandomPercentagesEnum::STAR_COLUMNS_TRUE },
{ "star_columns_true_lambda", RandomPercentagesEnum::STAR_COLUMNS_TRUE_LAMBDA },
Expand Down
52 changes: 26 additions & 26 deletions src/statement_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ unique_ptr<QueryNode> StatementGenerator::GenerateQueryNode() {
// Table Ref
//===--------------------------------------------------------------------===//
unique_ptr<TableRef> StatementGenerator::GenerateTableRef() {
if (RandomPercentage(60)) {
if (RandomPercentage(config[RandomPercentagesEnum::TABLE_REF_BASE_TABLE_REF_PERC])) {
return GenerateBaseTableRef();
}
if (RandomPercentage(20)) {
if (RandomPercentage(config[RandomPercentagesEnum::TABLE_REF_EXPRESSION_LIST_REF])) {
return GenerateExpressionListRef();
}
if (RandomPercentage(40)) {
if (RandomPercentage(config[RandomPercentagesEnum::TABLE_REF_JOIN_REF])) {
return GenerateJoinRef();
}
switch (RandomValue(3)) {
Expand Down Expand Up @@ -500,13 +500,13 @@ unique_ptr<TableRef> StatementGenerator::GenerateExpressionListRef() {

unique_ptr<TableRef> StatementGenerator::GenerateJoinRef() {
JoinRefType join_ref;
if (RandomPercentage(10)) {
if (RandomPercentage(config[RandomPercentagesEnum::JOIN_REF_CROSS])) {
join_ref = JoinRefType::CROSS;
} else if (RandomPercentage(10)) {
} else if (RandomPercentage(config[RandomPercentagesEnum::JOIN_REF_ASOF])) {
join_ref = JoinRefType::ASOF;
} else if (RandomPercentage(10)) {
} else if (RandomPercentage(config[RandomPercentagesEnum::JOIN_REF_NATURAL])) {
join_ref = JoinRefType::NATURAL;
} else if (RandomPercentage(10)) {
} else if (RandomPercentage(config[RandomPercentagesEnum::JOIN_REF_POSITIONAL])) {
join_ref = JoinRefType::POSITIONAL;
} else {
join_ref = JoinRefType::REGULAR;
Expand All @@ -515,7 +515,7 @@ unique_ptr<TableRef> StatementGenerator::GenerateJoinRef() {
join->left = GenerateTableRef();
join->right = GenerateTableRef();
if (join_ref != JoinRefType::CROSS && join_ref != JoinRefType::NATURAL) {
if (RandomPercentage(70)) {
if (RandomPercentage(config[RandomPercentagesEnum::JOIN_REF_GENERAL_EXPRESSION])) {
join->condition = GenerateExpression();
} else {
while (true) {
Expand Down Expand Up @@ -658,13 +658,13 @@ class ExpressionDepthChecker {

unique_ptr<ParsedExpression> StatementGenerator::GenerateExpression() {
ExpressionDepthChecker checker(*this);
if (RandomPercentage(50) || RandomPercentage(expression_depth + depth * 5)) {
if (RandomPercentage(config[RandomPercentagesEnum::EXPRESSION_COLUMN_REF]) || RandomPercentage(expression_depth + depth * 5)) {
return GenerateColumnRef();
}
if (RandomPercentage(30)) {
if (RandomPercentage(config[RandomPercentagesEnum::EXPRESSION_CONSTANT])) {
return GenerateConstant();
}
if (RandomPercentage(3)) {
if (RandomPercentage(config[RandomPercentagesEnum::EXPRESSION_SUBQUERY])) {
return GenerateSubquery();
}
switch (RandomValue(9)) {
Expand Down Expand Up @@ -692,10 +692,10 @@ unique_ptr<ParsedExpression> StatementGenerator::GenerateExpression() {
}

Value StatementGenerator::GenerateConstantValue() {
if (RandomPercentage(50)) {
if (RandomPercentage(config[RandomPercentagesEnum::CONSTANT_VALUE_BIGINT)) {

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Linux (linux_amd64_gcc4, quay.io/pypa/manylinux2014_x86_64, x64-linux)

expected ‘]’ before ‘)’ token

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / Linux (linux_amd64_gcc4, quay.io/pypa/manylinux2014_x86_64, x64-linux)

expected ‘]’ before ‘)’ token

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected ']'

Check failure on line 695 in src/statement_generator.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected ']'
return Value::BIGINT(RandomValue(9999));
}
if (RandomPercentage(30)) {
if (RandomPercentage(config[RandomPercentagesEnum::CONSTANT_VALUE_TO_STRING])) {
return Value(UUID::ToString(UUID::GenerateRandomUUID(RandomEngine::Get(context))));
}
auto &val = Choose(generator_context->test_types);
Expand Down Expand Up @@ -781,20 +781,20 @@ unique_ptr<ParsedExpression> StatementGenerator::GenerateFunction() {
if (actual_function.varargs.id() != LogicalTypeId::INVALID) {
max_parameters += 5;
}
if (RandomPercentage(10) && !in_window) {
if (RandomPercentage(config[RandomPercentagesEnum::FUNCTION_AGGREGATE_WINDOW_FUNCTION]) && !in_window) {
return GenerateWindowFunction(&actual_function);
}
if (in_aggregate) {
// we cannot nest aggregates
return GenerateColumnRef();
}
checker = make_uniq<AggregateChecker>(*this);
filter = RandomExpression(10);
if (RandomPercentage(10)) {
filter = RandomExpression(config[RandomPercentagesEnum::FUNCTION_AGGREGATE_FILTER]);
if (RandomPercentage(config[RandomPercentagesEnum::FUNCTION_AGGREGATE_ORDER_BY])) {
// generate order by
order_bys = GenerateOrderBy();
}
if (RandomPercentage(10)) {
if (RandomPercentage(config[RandomPercentagesEnum::FUNCTION_AGGREGATE_DISTINCT])) {
distinct = true;
}
break;
Expand Down Expand Up @@ -973,15 +973,15 @@ unique_ptr<ParsedExpression> StatementGenerator::GenerateWindowFunction(optional
WindowChecker checker(*this);
auto result = make_uniq<WindowExpression>(type, INVALID_CATALOG, INVALID_SCHEMA, std::move(name));
result->children = GenerateChildren(min_parameters, max_parameters);
while (RandomPercentage(50)) {
while (RandomPercentage(config[RandomPercentagesEnum::WINDOW_FUNCTION_PARTITIONS])) {
result->partitions.push_back(GenerateExpression());
}
if (RandomPercentage(30)) {
if (RandomPercentage(config[RandomPercentagesEnum::WINDOW_FUNCTION_ORDERS])) {
result->orders = std::move(GenerateOrderBy()->orders);
}
if (function) {
result->filter_expr = RandomExpression(30);
if (RandomPercentage(30)) {
result->filter_expr = RandomExpression(config[RandomPercentagesEnum::WINDOW_FUNCTION_FILTER_EXPRESSION]);
if (RandomPercentage(config[RandomPercentagesEnum::WINDOW_FUNCTION_IGNORE_NULLS])) {
result->ignore_nulls = true;
}
}
Expand Down Expand Up @@ -1018,8 +1018,8 @@ unique_ptr<ParsedExpression> StatementGenerator::GenerateWindowFunction(optional
switch (type) {
case ExpressionType::WINDOW_LEAD:
case ExpressionType::WINDOW_LAG:
result->offset_expr = RandomExpression(30);
result->default_expr = RandomExpression(30);
result->offset_expr = RandomExpression(config[RandomPercentagesEnum::WINDOW_FUNCTION_RESULT_OFFSET]);
result->default_expr = RandomExpression(config[RandomPercentagesEnum::WINDOW_FUNCTION_RESULT_DEFAULT]);
break;
default:
break;
Expand Down Expand Up @@ -1054,19 +1054,19 @@ unique_ptr<ParsedExpression> StatementGenerator::GenerateConjunction() {
unique_ptr<ParsedExpression> StatementGenerator::GenerateStar() {
auto result = make_uniq<StarExpression>();
if (!current_relation_names.empty()) {
if (RandomPercentage(10)) {
if (RandomPercentage(config[RandomPercentagesEnum::STAR_RELATION_NAME])) {
result->relation_name = GenerateRelationName();
}
}
if (!verification_enabled) {
while (RandomPercentage(20)) {
while (RandomPercentage(config[RandomPercentagesEnum::STAR_COLUMN_NAME_EXCLUDE_LIST])) {
auto column_name = GenerateColumnName();
if (column_name.empty()) {
break;
}
result->exclude_list.insert(column_name);
}
while (RandomPercentage(20)) {
while (RandomPercentage(config[RandomPercentagesEnum::STAR_COLUMN_NAME_REPLACE_LIST])) {
auto column_name = GenerateColumnName();
if (column_name.empty()) {
break;
Expand Down

0 comments on commit db0645b

Please sign in to comment.