Merge pull request #29755 from Joeywzr/new_func

add function getOSKernelVersion
This commit is contained in:
Maksim Kita 2021-10-10 01:12:54 +03:00 committed by GitHub
commit daf9cf12d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 0 deletions

View File

@ -81,6 +81,7 @@ void registerFunctionQueryID(FunctionFactory & factory);
void registerFunctionInitialQueryID(FunctionFactory & factory); void registerFunctionInitialQueryID(FunctionFactory & factory);
void registerFunctionServerUUID(FunctionFactory &); void registerFunctionServerUUID(FunctionFactory &);
void registerFunctionZooKeeperSessionUptime(FunctionFactory &); void registerFunctionZooKeeperSessionUptime(FunctionFactory &);
void registerFunctionGetOSKernelVersion(FunctionFactory &);
#if USE_ICU #if USE_ICU
void registerFunctionConvertCharset(FunctionFactory &); void registerFunctionConvertCharset(FunctionFactory &);
@ -162,6 +163,7 @@ void registerFunctionsMiscellaneous(FunctionFactory & factory)
registerFunctionInitialQueryID(factory); registerFunctionInitialQueryID(factory);
registerFunctionServerUUID(factory); registerFunctionServerUUID(factory);
registerFunctionZooKeeperSessionUptime(factory); registerFunctionZooKeeperSessionUptime(factory);
registerFunctionGetOSKernelVersion(factory);
#if USE_ICU #if USE_ICU
registerFunctionConvertCharset(factory); registerFunctionConvertCharset(factory);

View File

@ -7,6 +7,10 @@
#include <Common/DNSResolver.h> #include <Common/DNSResolver.h>
#include <base/DateLUT.h> #include <base/DateLUT.h>
#if defined(OS_LINUX)
# include <Poco/Environment.h>
#endif
#if !defined(ARCADIA_BUILD) #if !defined(ARCADIA_BUILD)
# include <Common/config_version.h> # include <Common/config_version.h>
#endif #endif
@ -96,6 +100,17 @@ namespace
} }
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionZooKeeperSessionUptime>(context); } static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionZooKeeperSessionUptime>(context); }
}; };
#if defined(OS_LINUX)
class FunctionGetOSKernelVersion : public FunctionConstantBase<FunctionGetOSKernelVersion, String, DataTypeString>
{
public:
static constexpr auto name = "getOSKernelVersion";
explicit FunctionGetOSKernelVersion(ContextPtr context) : FunctionConstantBase(context, Poco::Environment::osName() + " " + Poco::Environment::osVersion()) {}
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionGetOSKernelVersion>(context); }
};
#endif
} }
@ -143,5 +158,14 @@ void registerFunctionZooKeeperSessionUptime(FunctionFactory & factory)
factory.registerFunction<FunctionZooKeeperSessionUptime>(); factory.registerFunction<FunctionZooKeeperSessionUptime>();
} }
void registerFunctionGetOSKernelVersion([[maybe_unused]] FunctionFactory & factory)
{
#if defined(OS_LINUX)
factory.registerFunction<FunctionGetOSKernelVersion>();
#endif
}
} }

View File

@ -0,0 +1 @@
WITH splitByChar(' ', getOSKernelVersion()) AS version_pair SELECT version_pair[1]