From db0645b145d8e0b1a798fcdabe2cbdf2aa4d2aa8 Mon Sep 17 00:00:00 2001 From: Zuleykha Pavlichenkova Date: Sun, 27 Oct 2024 22:51:30 +0100 Subject: [PATCH] add more values from the config file --- config_nested.json | 3 ++ src/include/random_nums_config.hpp | 3 ++ src/random_nums_config.cpp | 3 ++ src/statement_generator.cpp | 52 +++++++++++++++--------------- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/config_nested.json b/config_nested.json index bf2a2c0..fa4c6cd 100644 --- a/config_nested.json +++ b/config_nested.json @@ -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" @@ -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", diff --git a/src/include/random_nums_config.hpp b/src/include/random_nums_config.hpp index 251a4ac..1ad456d 100644 --- a/src/include/random_nums_config.hpp +++ b/src/include/random_nums_config.hpp @@ -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, @@ -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, @@ -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, diff --git a/src/random_nums_config.cpp b/src/random_nums_config.cpp index 60344d5..8a96e42 100644 --- a/src/random_nums_config.cpp +++ b/src/random_nums_config.cpp @@ -55,15 +55,18 @@ unordered_map 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 }, diff --git a/src/statement_generator.cpp b/src/statement_generator.cpp index aac0eb5..8075195 100644 --- a/src/statement_generator.cpp +++ b/src/statement_generator.cpp @@ -434,13 +434,13 @@ unique_ptr StatementGenerator::GenerateQueryNode() { // Table Ref //===--------------------------------------------------------------------===// unique_ptr 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)) { @@ -500,13 +500,13 @@ unique_ptr StatementGenerator::GenerateExpressionListRef() { unique_ptr 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; @@ -515,7 +515,7 @@ unique_ptr 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) { @@ -658,13 +658,13 @@ class ExpressionDepthChecker { unique_ptr 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)) { @@ -692,10 +692,10 @@ unique_ptr StatementGenerator::GenerateExpression() { } Value StatementGenerator::GenerateConstantValue() { - if (RandomPercentage(50)) { + if (RandomPercentage(config[RandomPercentagesEnum::CONSTANT_VALUE_BIGINT)) { 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); @@ -781,7 +781,7 @@ unique_ptr 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) { @@ -789,12 +789,12 @@ unique_ptr StatementGenerator::GenerateFunction() { return GenerateColumnRef(); } checker = make_uniq(*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; @@ -973,15 +973,15 @@ unique_ptr StatementGenerator::GenerateWindowFunction(optional WindowChecker checker(*this); auto result = make_uniq(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; } } @@ -1018,8 +1018,8 @@ unique_ptr 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; @@ -1054,19 +1054,19 @@ unique_ptr StatementGenerator::GenerateConjunction() { unique_ptr StatementGenerator::GenerateStar() { auto result = make_uniq(); 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;