Skip to content

Commit 052b125

Browse files
committed
Log UDF name
1 parent 15ad477 commit 052b125

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Functions/UserDefined/UserDefinedExecutableFunctionFactory.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#include <filesystem>
44

5+
#include <Common/CurrentThread.h>
56
#include <Common/filesystemHelpers.h>
67
#include <Common/FieldVisitorToString.h>
78
#include <Common/quoteString.h>
9+
#include <Core/Settings.h>
810
#include <DataTypes/FieldToDataType.h>
911

1012
#include <Processors/Sources/ShellCommandSource.h>
@@ -28,6 +30,11 @@ namespace ErrorCodes
2830
extern const int BAD_ARGUMENTS;
2931
}
3032

33+
namespace Setting
34+
{
35+
extern const SettingsBool log_queries;
36+
}
37+
3138
namespace
3239
{
3340

@@ -245,6 +252,14 @@ FunctionOverloadResolverPtr UserDefinedExecutableFunctionFactory::get(const Stri
245252
const auto & loader = context->getExternalUserDefinedExecutableFunctionsLoader();
246253
auto executable_function = std::static_pointer_cast<const UserDefinedExecutableFunction>(loader.load(function_name));
247254
auto function = std::make_shared<UserDefinedFunction>(std::move(executable_function), std::move(context), std::move(parameters));
255+
256+
if (CurrentThread::isInitialized())
257+
{
258+
auto query_context = CurrentThread::get().getQueryContext();
259+
if (query_context && query_context->getSettingsRef()[Setting::log_queries])
260+
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::Function, function_name);
261+
}
262+
248263
return std::make_unique<FunctionToOverloadResolverAdaptor>(std::move(function));
249264
}
250265

@@ -257,6 +272,14 @@ FunctionOverloadResolverPtr UserDefinedExecutableFunctionFactory::tryGet(const S
257272
{
258273
auto executable_function = std::static_pointer_cast<const UserDefinedExecutableFunction>(load_result.object);
259274
auto function = std::make_shared<UserDefinedFunction>(std::move(executable_function), std::move(context), std::move(parameters));
275+
276+
if (CurrentThread::isInitialized())
277+
{
278+
auto query_context = CurrentThread::get().getQueryContext();
279+
if (query_context && query_context->getSettingsRef()[Setting::log_queries])
280+
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::Function, function_name);
281+
}
282+
260283
return std::make_unique<FunctionToOverloadResolverAdaptor>(std::move(function));
261284
}
262285

0 commit comments

Comments
 (0)