add FunctionOSKernelVersion

This commit is contained in:
WangZengrui 2021-10-09 16:49:49 +08:00
parent 0e9bbc4d43
commit 2204597cfe
4 changed files with 26 additions and 52 deletions

View File

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

View File

@ -7,6 +7,10 @@
#include <Common/DNSResolver.h>
#include <base/DateLUT.h>
#if defined(OS_LINUX)
# include <Poco/Environment.h>
#endif
#if !defined(ARCADIA_BUILD)
# include <Common/config_version.h>
#endif
@ -93,6 +97,17 @@ namespace
explicit FunctionZooKeeperSessionUptime(ContextPtr context) : FunctionConstantBase(context, context->getZooKeeperSessionUptime()) {}
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionZooKeeperSessionUptime>(context); }
};
#if defined(OS_LINUX)
class FunctionOSKernelVersion : public FunctionConstantBase<FunctionOSKernelVersion, String, DataTypeString>
{
public:
static constexpr auto name = "OSKernelVersion";
explicit FunctionOSKernelVersion(ContextPtr context) : FunctionConstantBase(context, Poco::Environment::osName() + " " + Poco::Environment::osVersion()) {}
static FunctionPtr create(ContextPtr context) { return std::make_shared<FunctionOSKernelVersion>(context); }
};
#endif
}
@ -140,5 +155,14 @@ void registerFunctionZooKeeperSessionUptime(FunctionFactory & factory)
factory.registerFunction<FunctionZooKeeperSessionUptime>();
}
void registerFunctionOSKernelVersion(FunctionFactory & factory)
{
#if defined(OS_LINUX)
factory.registerFunction<FunctionOSKernelVersion>();
#endif
}
}

View File

@ -1,31 +0,0 @@
#if defined(OS_LINUX)
#include <Interpreters/getOSKernelVersion.h>
namespace DB
{
namespace ErrorCodes
{
extern const int SYSTEM_ERROR;
}
String getOSKernelVersion()
{
struct utsname os_kernel_info;
int buf = uname(&os_kernel_info);
if (buf < 0)
{
throw Exception(
"EFAULT buffer is not valid.",
ErrorCodes::SYSTEM_ERROR);
}
else
{
return String(os_kernel_info.sysname) + " " + String(os_kernel_info.release);
}
}
}
#endif

View File

@ -1,21 +0,0 @@
#pragma once
#if defined(OS_LINUX)
#include <Common/typeid_cast.h>
#include <string>
#include <sys/utsname.h>
namespace DB
{
/// Returns String with OS Kernel version.
/* To get name and information about current kernel.
For simplicity, the function can be implemented only for Linux.
*/
String getOSKernelVersion();
}
#endif