From 4373ed0f987711af60fbe73b597683ee2eb87b5b Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Mon, 18 Sep 2023 15:26:54 +0000 Subject: [PATCH] Added field "is_deterministic" to system.functions --- .../System/StorageSystemFunctions.cpp | 57 ++++++++++++------- .../02117_show_create_table_system.reference | 1 + 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/Storages/System/StorageSystemFunctions.cpp b/src/Storages/System/StorageSystemFunctions.cpp index 0c609d84da3..37d536ff6b1 100644 --- a/src/Storages/System/StorageSystemFunctions.cpp +++ b/src/Storages/System/StorageSystemFunctions.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -29,6 +30,7 @@ namespace MutableColumns & res_columns, const String & name, UInt64 is_aggregate, + std::optional is_deterministic, const String & create_query, FunctionOrigin function_origin, const Factory & factory) @@ -36,53 +38,58 @@ namespace res_columns[0]->insert(name); res_columns[1]->insert(is_aggregate); + if (!is_deterministic.has_value()) + res_columns[2]->insertDefault(); + else + res_columns[2]->insert(*is_deterministic); + if constexpr (std::is_same_v || std::is_same_v) { - res_columns[2]->insert(false); - res_columns[3]->insertDefault(); + res_columns[3]->insert(false); + res_columns[4]->insertDefault(); } else { - res_columns[2]->insert(factory.isCaseInsensitive(name)); + res_columns[3]->insert(factory.isCaseInsensitive(name)); if (factory.isAlias(name)) - res_columns[3]->insert(factory.aliasTo(name)); + res_columns[4]->insert(factory.aliasTo(name)); else - res_columns[3]->insertDefault(); + res_columns[4]->insertDefault(); } - res_columns[4]->insert(create_query); - res_columns[5]->insert(static_cast(function_origin)); + res_columns[5]->insert(create_query); + res_columns[6]->insert(static_cast(function_origin)); if constexpr (std::is_same_v) { if (factory.isAlias(name)) { - res_columns[6]->insertDefault(); res_columns[7]->insertDefault(); res_columns[8]->insertDefault(); res_columns[9]->insertDefault(); res_columns[10]->insertDefault(); res_columns[11]->insertDefault(); + res_columns[12]->insertDefault(); } else { auto documentation = factory.getDocumentation(name); - res_columns[6]->insert(documentation.description); - res_columns[7]->insert(documentation.syntax); - res_columns[8]->insert(documentation.argumentsAsString()); - res_columns[9]->insert(documentation.returned_value); - res_columns[10]->insert(documentation.examplesAsString()); - res_columns[11]->insert(documentation.categoriesAsString()); + res_columns[7]->insert(documentation.description); + res_columns[8]->insert(documentation.syntax); + res_columns[9]->insert(documentation.argumentsAsString()); + res_columns[10]->insert(documentation.returned_value); + res_columns[11]->insert(documentation.examplesAsString()); + res_columns[12]->insert(documentation.categoriesAsString()); } } else { - res_columns[6]->insertDefault(); res_columns[7]->insertDefault(); res_columns[8]->insertDefault(); res_columns[9]->insertDefault(); res_columns[10]->insertDefault(); res_columns[11]->insertDefault(); + res_columns[12]->insertDefault(); } } } @@ -102,6 +109,7 @@ NamesAndTypesList StorageSystemFunctions::getNamesAndTypes() return { {"name", std::make_shared()}, {"is_aggregate", std::make_shared()}, + {"is_deterministic", std::make_shared(std::make_shared())}, {"case_insensitive", std::make_shared()}, {"alias_to", std::make_shared()}, {"create_query", std::make_shared()}, @@ -121,14 +129,25 @@ void StorageSystemFunctions::fillData(MutableColumns & res_columns, ContextPtr c const auto & function_names = functions_factory.getAllRegisteredNames(); for (const auto & function_name : function_names) { - fillRow(res_columns, function_name, UInt64(0), "", FunctionOrigin::SYSTEM, functions_factory); + std::optional is_deterministic; + try + { + is_deterministic = functions_factory.tryGet(function_name, context)->isDeterministic(); + } + catch (...) + { + /// Some functions throw because they need special configuration or setup before use. + /// Ignore the exception and simply show is_deterministic = NULL. + } + + fillRow(res_columns, function_name, 0, is_deterministic, "", FunctionOrigin::SYSTEM, functions_factory); } const auto & aggregate_functions_factory = AggregateFunctionFactory::instance(); const auto & aggregate_function_names = aggregate_functions_factory.getAllRegisteredNames(); for (const auto & function_name : aggregate_function_names) { - fillRow(res_columns, function_name, UInt64(1), "", FunctionOrigin::SYSTEM, aggregate_functions_factory); + fillRow(res_columns, function_name, 1, {1}, "", FunctionOrigin::SYSTEM, aggregate_functions_factory); } const auto & user_defined_sql_functions_factory = UserDefinedSQLFunctionFactory::instance(); @@ -136,14 +155,14 @@ void StorageSystemFunctions::fillData(MutableColumns & res_columns, ContextPtr c for (const auto & function_name : user_defined_sql_functions_names) { auto create_query = queryToString(user_defined_sql_functions_factory.get(function_name)); - fillRow(res_columns, function_name, UInt64(0), create_query, FunctionOrigin::SQL_USER_DEFINED, user_defined_sql_functions_factory); + fillRow(res_columns, function_name, 0, {0}, create_query, FunctionOrigin::SQL_USER_DEFINED, user_defined_sql_functions_factory); } const auto & user_defined_executable_functions_factory = UserDefinedExecutableFunctionFactory::instance(); const auto & user_defined_executable_functions_names = user_defined_executable_functions_factory.getRegisteredNames(context); for (const auto & function_name : user_defined_executable_functions_names) { - fillRow(res_columns, function_name, UInt64(0), "", FunctionOrigin::EXECUTABLE_USER_DEFINED, user_defined_executable_functions_factory); + fillRow(res_columns, function_name, 0, {0}, "", FunctionOrigin::EXECUTABLE_USER_DEFINED, user_defined_executable_functions_factory); } } diff --git a/tests/queries/0_stateless/02117_show_create_table_system.reference b/tests/queries/0_stateless/02117_show_create_table_system.reference index 9b633314bd3..a6617cf44c7 100644 --- a/tests/queries/0_stateless/02117_show_create_table_system.reference +++ b/tests/queries/0_stateless/02117_show_create_table_system.reference @@ -283,6 +283,7 @@ CREATE TABLE system.functions ( `name` String, `is_aggregate` UInt8, + `is_deterministic` Nullable(UInt8), `case_insensitive` UInt8, `alias_to` String, `create_query` String,